What is the output of the program given below

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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is restrict keyword in c?

638


How would you use the functions fseek(), freed(), fwrite() and ftell()?

699


What are local static variables?

616


Explain what are run-time errors?

605


What tq means in chat?

579






What are the advantages of c language?

662


Can i use “int” data type to store the value 32768? Why?

754


How do you define a function?

579


write a program to print largest number of each row of a 2D array

1866


What are the advantages and disadvantages of c language?

556


What is meant by preprocessor in c?

528


Why do we use int main?

602


How will you print TATA alone from TATA POWER using string copy and concate commands in C?

916


How is a null pointer different from a dangling pointer?

555


What is the code in while loop that returns the output of given code?

1305