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 |
Explain how can you determine the size of an allocated portion of memory?
what is the output of the code and how? main() { int *ptr,x; x=sizeof(ptr); printf("%d",x); }
what is op? for(c=0;c=1000;c++) printf("%c",c);
write a C program to print the program itself ?!
du u know test pattern for robosoft? Plz share
1 Answers RoboSoft, TATA, Wipro,
How can you check to see whether a symbol is defined?
give one ip, find out which contry
struct ptr { int a; char b; int *p; }abc; what is d sizeof structure without using "sizeof" operator??
What is operator promotion?
What does the characters “r” and “w” mean when writing programs that will make use of files?
what is the use of getch() function in C program.. difference b/w getch() and getche()??
29 Answers HCL, IBM, Infosys, TCS, Wipro,
main() {char a[10]={1,2,3,4,5,6};int x; for(x=0;x<4;x++){ b[x]=x+'a';} printf("%s",b);}