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



int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE)..

Answer / 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

int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE)..

Answer / dnyaneshwar

1

Is This Answer Correct ?    3 Yes 15 No

Post New Answer

More C Interview Questions

How to get string length of given string in c?

0 Answers  


What is a class?

3 Answers  


What is #include conio h?

0 Answers  


Why isn't any of this standardized in c? Any real program has to do some of these things.

0 Answers  


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); }

4 Answers  






Write a program to find factorial of a number using recursive function.

0 Answers   Global Logic, TCS,


what is the hexidecimal number of 4100?

16 Answers   Google,


Tell me what is null pointer in c?

0 Answers  


code for bubble sort?

1 Answers  


What is meant by type casting?

0 Answers  


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?

2 Answers   HP,


Categories