int array[]={1,2,3,4,5,6,7,8};
#define SIZE (sizeof(array)/sizeof(int))
main()
{
if(-1<=SIZE) printf("1");
else printf("2");
}
Answer Posted / c.p.senthil
program prints "2"
Here sizeof returns unsigned int value
so sizeof(array)/sizeof(int)
=> 32(unsigned int)/4(unsigned int)
=> 8 (unsigned int value)
During comparison, the datatypes are different on both sides of if condition
-1(signed int) <= 8(unsigned int)
so by rule of type conversion in c,
signed int gets converted to unsigned int
hence expression becomes
0xFFFFFFFF(unsigned int equivalent of -1) <= 8(unsigned int)
Hence overall condition becomes FALSE
Is This Answer Correct ? | 72 Yes | 6 No |
Post New Answer View All Answers
How to write a code for reverse of string without using string functions?
Why is this loop always executing once?
Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)
Does c have circular shift operators?
can we implement multi-threads in c.
What does the message "automatic aggregate intialization is an ansi feature" mean?
What is the benefit of using const for declaring constants?
Differentiate between calloc and malloc.
What is the difference between the expression “++a” and “a++”?
What is file in c preprocessor?
What is the difference between procedural and declarative language?
What is a wrapper function in c?
Why is c called c not d or e?
Can we declare function inside main?
why programs in c are running with out #include