edited by
227 views
2 votes
2 votes

What is the output of the following program?

#include<stdio.h>
int main()
{
    int i=0;
    for(i++;i==1;i=2)
    printf("Inside loop ");
    printf("Outside loop");
    return 0;
}
  1. Inside loop Outside loop
  2. Outside loop
  3. Infinite times Inside loop
  4. Syntax error in for loop statement
edited by

1 Answer

1 votes
1 votes
If we use the $++$ operator as prefix like$: ++var,$ the value of var is incremented by $1$ then, it returns the value.

If we use the $++$ operator as postfix like$: var++,$ the original value of var is returned first then, var is incremented by $1.$

The $--$ operator works in a similar way like the $++$ operator except it decreases the value by $1.$

Now, for first iteration, $i = 1$, condition satisfies and prints "Inside loop".

For second iteration the value of $i = 2,$ and condition does not satisfy and the loop exits.

Then "Outside loop" will be printed.

So, the correct answer is $(A).$
Answer:

Related questions

1 votes
1 votes
1 answer
3
gatecse asked Feb 1, 2021
154 views
What is the value returned by the below function when invoked as $fun(20,1)?$int fun(int x,int y) { if(x/2==0) return 0; else if(x%2) return fun(x/2,3*y) + x + y; else re...