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

read the folllowing code # define MAX 100 # define MIN 100 .... .... if(x>MAX) x=1; else if(x<MIN) x=-1; x=50; if the initial value of x=200,what is the vlaue after executing this code? a.200 b.1 c.-1 d.50

4 Answers   TCS,


What is wrong with this initialization?

0 Answers  


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

0 Answers  


What are header files why are they important?

0 Answers  


what is difference between getchar,putchar functions and printf and scanf function? does putchar show output only when input given to it

5 Answers   DIT,






Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass.

11 Answers   Microsoft,


How is a two dimensional array passed to function when the order of matrix is not known at complie time?

1 Answers   CSC,


What is size of union in c?

0 Answers  


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

0 Answers   Wilco,


3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r

3 Answers   Huawei,


34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

0 Answers  


Look at the Code: #include<string.h> void main() { char s1[]="abcd"; char s2[10]; char s3[]="efgh"; int i; clrscr(); i=strcmp(strcat(s3,ctrcpy(s2,s1))strcat(s3,"abcd")); printf("%d",i); } What will be the output? A)No output B) A Non Integer C)0 D) Garbage

7 Answers   Accenture,


Categories