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

what is the output of the below program & why ? #include<stdio.h> void main() { int a=10,b=20,c=30; printf("%d",scanf("%d%d%d",&a,&b,&c)); }

6 Answers   CSC, IIIT,


Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..

2 Answers  


what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }

10 Answers  


how to swap 3 nos without using temporary variable

4 Answers   Satyam,


void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }

3 Answers  






How to read a directory in a C program?

4 Answers  


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


WAP to display 1,2,3,4,5........N

2 Answers  


write a c program to Create a mail account by taking the username, password, confirm password, secret_question, secret_answer and phone number. Allow users to register, login and reset password(based on secret question). Display the user accounts and their details .

2 Answers  


Write a program to model an exploding firecracker in the xy plane using a particle system

0 Answers   HCL,


How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com

11 Answers   Deshaw, Infosys,


main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }

1 Answers  


Categories