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 |
How to get string length of given string in c?
What is a class?
What is #include conio h?
Why isn't any of this standardized in c? Any real program has to do some of these things.
what would be the output of the follwing struct st { char name[20]; int i; float f; }; main() { struct st emp = {"forum"}; printf("%d %f",emp.i,emp.f); }
Write a program to find factorial of a number using recursive function.
what is the hexidecimal number of 4100?
Tell me what is null pointer in c?
code for bubble sort?
What is meant by type casting?
1.)how to find d most repeated word in a string? string ="how do you do"?? output should be do
1 Answers AAS, Nagarro, Vuram,
how 2 compile & execute c program with out using editor?