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 / 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 ? | 11 Yes | 1 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 / 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 |
Did c have any year 2000 problems?
main() { intj; while9j<=10) { printf("\n%d",j); j=j+1; } }
largest Of three Number using without if condition?
Explain #pragma statements.
What are the types of variables in c?
Is c easier than java?
What is the process of writing the null pointer?
what is the defrenece between structure and union
Write a program to reverse a given number in c?
Is there a way to jump out of a function or functions?
What are predefined functions in c?
writw a program to insert an element in the begning of a doubly linked list