What is the output of the program given below

#include<stdio.h>
main()
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}




Answers were Sorted based on User's Feedback



Answer / sh college,thevara

-128

Is This Answer Correct ?    30 Yes 8 No

Answer / sharan

#include<stdio.h>
main()
{
char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}

Here the CATCH is semicolon after for
so maximum positive value for the signed char is 127.
Hence it loops 127 times after that value of i wraps to
negative value that is -128.

Thus it prints -128.

Is This Answer Correct ?    10 Yes 1 No

Answer / rani

output is

-128

Is This Answer Correct ?    10 Yes 3 No




Answer / karan

it will display the garbage value bcoz there is semicolon
at end of the for loop which will be
-128

Is This Answer Correct ?    3 Yes 0 No

Answer / gajanandon

after for there is semicolon...means empty statement. So no
effect of printf.
so for runs till i (char value) increments in positive
direction and terminates once it exceeds 127 (char
limitation).
Hence finally printf will execute and then prints -128.

Is This Answer Correct ?    3 Yes 0 No

Answer / stuti

1

Is This Answer Correct ?    2 Yes 0 No

Answer / aryan

-128

Is This Answer Correct ?    1 Yes 0 No

Answer / prasanna kumar [cse dept. kln

i think the program will give the output as 0 or null....
because i=0 is in int datatype but in this program it is
declared as character datatype so it will give the output as
0 or null and it will goes for only one time after wards it
will incremented and goes infinitely....

Is This Answer Correct ?    0 Yes 0 No

Answer / akash dhal

initialized with 0
in for loop ist time condition satisfied so print 0,like
this 127 will be printed .as it is a signed no. so 127+1 is
-128 so condition false come out of the loop.

Is This Answer Correct ?    0 Yes 0 No

Answer / vennila

*
**
***
****

Is This Answer Correct ?    0 Yes 0 No

Post New Answer



More C Interview Questions

int arr[] = {1,2,3,4} int *ptr=arr; *(arr+3) = *++ptr + *ptr++; Final contents of arr[]

6 Answers   Hughes,


whether itis a structured language?

1 Answers   Microsoft,


what is differnence b/w macro & functions

1 Answers  


1,1,5,17,61,217,?,?.

3 Answers   Apple,


How can I find leaf node with smallest level in a binary tree?

1 Answers  






can u give me the good and very optimised code for a car racing game?

0 Answers  


how to set Nth bit of variable by using MACRO

3 Answers   HCL,


what is real time system?what is the differance between hard and soft real time systems

2 Answers  


matrix multiplication fails introspect the causes for its failure and write down the possible reasons for its failurein c language.

4 Answers   TCS,


what is the output of the program and explain why?? #include<stdio.h> void main ( ) { int k=4,j=0: switch (k) { case 3; j=300; case 4: j=400: case 5: j=500; } printf (ā€œ%d\nā€,j); }

14 Answers   Oracle,


Q.11 Generate the following pattern using code in any language(c/c++/java) for n no. of rows 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

2 Answers  


which one is highest Priority in c? a)=,b)+,c)++,d)==

4 Answers  






Categories