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
Explain enumerated types in c language?
What is a global variable in c?
Tell us bitwise shift operators?
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
What is this infamous null pointer, anyway?
can any one provide me the notes of data structure for ignou cs-62 paper
What are the 5 organizational structures?
What are shell structures used for?
Can you add pointers together? Why would you?
What is the best way to comment out a section of code that contains comments?
What is a struct c#?
What language is lisp written in?
Explain can you assign a different address to an array tag?
What are the advantages and disadvantages of pointers?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.