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

Explain enumerated types in c language?

600


What is a global variable in c?

586


Tell us bitwise shift operators?

592


An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

683


What is this infamous null pointer, anyway?

605






can any one provide me the notes of data structure for ignou cs-62 paper

1697


What are the 5 organizational structures?

564


What are shell structures used for?

595


Can you add pointers together? Why would you?

636


What is the best way to comment out a section of code that contains comments?

774


What is a struct c#?

599


What language is lisp written in?

611


Explain can you assign a different address to an array tag?

640


What are the advantages and disadvantages of pointers?

570


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2602