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
What is identifiers in c with examples?
What is dynamic variable in c?
Here is a good puzzle: how do you write a program which produces its own source code as output?
What is unsigned int in c?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What are the salient features of c languages?
What are the types of functions in c?
How do you generate random numbers in C?
How does free() know explain how much memory to release?
What the advantages of using Unions?
Is javascript written in c?
What is a spanning Tree?
Explain #pragma statements.
How can I remove the trailing spaces from a string?
we need to calculating INCOME TAX for the person. The INCOME TAX is as follows:- First $10000/- of income : 4% tax Next $10000/- of income : 8% tax Next $10000/- of income : 11.5% tax above $10, 00,00/- : 15% tax What is the Solution of this Question ?