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 |
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
Write a C++ program to give the number of days in each month according to what the user entered. example: the user enters June the program must count number of days from January up to June
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
Why static variable is used in c?
print the palindrome numbers in between 0 to n
Not all reserved words are written in lowercase. TRUE or FALSE?
write a program to rearrange the array such way that all even elements should come first and next come odd
int arr[] = {1,2,3,4} int *ptr=arr; *(arr+3) = *++ptr + *ptr++; Final contents of arr[]
How can I generate floating-point random numbers?
I have seen function declarations that look like this
Explain what are its uses in c programming?
How variables are declared in c?