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

How to write a code for reverse of string without using string functions?

1837


Why is this loop always executing once?

810


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

1039


Does c have circular shift operators?

968


can we implement multi-threads in c.

882


What does the message "automatic aggregate intialization is an ansi feature" mean?

929


What is the benefit of using const for declaring constants?

813


Differentiate between calloc and malloc.

1012


What is the difference between the expression “++a” and “a++”?

855


What is file in c preprocessor?

886


What is the difference between procedural and declarative language?

894


What is a wrapper function in c?

836


Why is c called c not d or e?

842


Can we declare function inside main?

760


why programs in c are running with out #include? some warnings are display in terminal but we execute the program we get answer why? eg: main() { printf("hello world "); }

1523