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


Please Help Members By Posting Answers For Below Questions

What is difference between Structure and Unions?

848


What is modifier & how many types of modifiers available in c?

790


WRITE A PROGRAM TO MERGE TWO SORTED ARRAY USING MERGE SORT TECHNIQUE..

1777


What is the stack in c?

873


Differentiate between a for loop and a while loop? What are it uses?

879






Why is it important to memset a variable, immediately after allocating memory to it ?

1751


Explain function?

831


Can include files be nested? How many levels deep can include files be nested?

843


What happens if a header file is included twice?

762


Who is the main contributor in designing the c language after dennis ritchie?

747


Explain what is the use of a semicolon (;) at the end of every program statement?

931


What is a lvalue

841


Explain what is a 'locale'?

769


What does c mean in standard form?

815


What does nil mean in c?

868