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


Please Help Members By Posting Answers For Below Questions

Write a program to print fibonacci series without using recursion?

860


Explain about the functions strcat() and strcmp()?

807


Explain how do you determine whether to use a stream function or a low-level function?

871


What is the benefit of using an enum rather than a #define constant?

961


What are types of functions?

793


What is the meaning of 2d in c?

849


write a program to copy the string using switch case?

2653


Is c still relevant?

867


What is pointer and structure in c?

800


Explain what are multibyte characters?

892


What is a pointer variable in c language?

869


a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

1016


What are predefined functions in c?

805


What is the best way to store flag values in a program?

817


What are the characteristics of arrays in c?

843