Logo 
Search:

C Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C ProgrammingRSS Feeds

C programming practical question 112

  Shared By: Adah Miller    Date: Jan 24    Category: C Programming    Views: 66

Answer:

What is the output of the program given below

main()
{
signed char i=0;
for(;i>=0;i++) ;
printf("%d\n",i);
}


Answer
-128


Explanation
Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. The inner loop executes to increment the value from 0 to 127 (the positive range of char) and then it rotates to the negative value of -128. The condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.

Share: 
 

Didn't find what you were looking for? Find more on C programming practical question 112 Or get search suggestion and latest updates.


Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: