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
difference between Low, Middle, High Level languages in c ?
What is the difference between constant pointer and constant variable?
c language interview questions & answer
I need a sort of an approximate strcmp routine?
What's the total generic pointer type?
How can I get back to the interactive keyboard if stdin is redirected?
What is function prototype in c language?
What are header files in c programming?
I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...
What is c preprocessor mean?
What standard functions are available to manipulate strings?
can anyone please tell about the nested interrupts?
Explain how can I prevent another program from modifying part of a file that I am modifying?
Whats s or c mean?
I need previous papers of CSC.......plz help out by posting them.......