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

What happens if a header file is included twice?

0 Answers  


How will you divide two numbers in a MACRO?

0 Answers   Apps Associates,


What does *p++ do?

0 Answers  


What is structure padding in c?

0 Answers  


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?

9 Answers  


what is an ERP?

2 Answers   Infotech,


Why array is used in c?

0 Answers  


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?

1 Answers  


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?

4 Answers   NMIMS, Wipro,


Once I have used freopen, how can I get the original stdout (or stdin) back?

0 Answers  


what is difference between ++(*p) and (*p)++

17 Answers   Accenture, HCL, IBM,


Categories