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
Write a program to print fibonacci series without using recursion?
Explain about the functions strcat() and strcmp()?
Explain how do you determine whether to use a stream function or a low-level function?
What is the benefit of using an enum rather than a #define constant?
What are types of functions?
What is the meaning of 2d in c?
write a program to copy the string using switch case?
Is c still relevant?
What is pointer and structure in c?
Explain what are multibyte characters?
What is a pointer variable in c language?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
What are predefined functions in c?
What is the best way to store flag values in a program?
What are the characteristics of arrays in c?