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
What is difference between Structure and Unions?
What is modifier & how many types of modifiers available in c?
WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..
What is the stack in c?
Differentiate between a for loop and a while loop? What are it uses?
Why is it important to memset a variable, immediately after allocating memory to it ?
Explain function?
Can include files be nested? How many levels deep can include files be nested?
What happens if a header file is included twice?
Who is the main contributor in designing the c language after dennis ritchie?
Explain what is the use of a semicolon (;) at the end of every program statement?
What is a lvalue
Explain what is a 'locale'?
What does c mean in standard form?
What does nil mean in c?