void main()

{

static int i;

while(i<=10)

(i>2)?i++:i--;

printf(“%d”, i);

}

Answers were Sorted based on User's Feedback



void main() { static int i; while(i<=10) (i>2)?i++:i--; ..

Answer / susie

Answer :

32767

Explanation:

Since i is static it is initialized to 0. Inside the while
loop the conditional operator evaluates to false, executing
i--. This continues till the integer value rotates to
positive value (32767). The while condition becomes false
and hence, comes out of the while loop, printing the i value.

Is This Answer Correct ?    7 Yes 2 No

void main() { static int i; while(i<=10) (i>2)?i++:i--; ..

Answer / prashanth

As i is static, it initially stores value 0.
as 0<=10 and in next stmt 0>2 is false so i-- is executed..
the loop continues till i=-32768 and when i=-32768 then
-32768>2 is false so i-- is executed..
As -32768-1 is equal to 32767. so i=32767 now..
while condition fails and it comes out of loop..
so the ans. is 32767.

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Code Interview Questions

void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }

1 Answers  


main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }

2 Answers  


#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?

1 Answers   Wipro,


main() { char a[4]="HELLO"; printf("%s",a); }

3 Answers   CSC,


Is the following code legal? struct a { int x; struct a b; }

1 Answers  






main() { int i = 3; for (;i++=0;) printf(“%d”,i); }

1 Answers   CSC,


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,


write a program for area of circumference of shapes

0 Answers  


main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }

2 Answers  


main() { char not; not=!2; printf("%d",not); }

1 Answers  


Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped

1 Answers   IBM,


There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen(“somefile.dat”,”r”); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }

1 Answers  


Categories