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
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
What do you mean by a sequential access file?
What is the use of printf() and scanf() functions?
What is the use of getchar functions?
Write a program to print fibonacci series without using recursion?
What is typeof in c?
Explain the binary height balanced tree?
What is indirection? How many levels of pointers can you have?
why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above
What is meant by 'bit masking'?
What does nil mean in c?
Are there any problems with performing mathematical operations on different variable types?
In a switch statement, explain what will happen if a break statement is omitted?
What will the preprocessor do for a program?
Why doesn't C support function overloading?