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");
}
Answers were Sorted based on User's Feedback
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 |
What happens if a header file is included twice?
How will you divide two numbers in a MACRO?
What does *p++ do?
What is structure padding in c?
52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?
what is an ERP?
Why array is used in c?
There is a number and when the last digit is moved to its first position the resultant number will be 50% higher than the original number.Find the number?
who is the father of C Language?
20 Answers CTS, UST,
An array name contains base address of the array. Can we change the base address of the array?
Once I have used freopen, how can I get the original stdout (or stdin) back?
what is difference between ++(*p) and (*p)++
17 Answers Accenture, HCL, IBM,