Open In App
Related Articles

Algorithms Quiz | SP2 Contest 1 | Question 1

Improve Article
Improve
Save Article
Save
Like Article
Like

Predict the output of below C program:




#include<stdio.h>
int main()
{
    int a = 5, b = 10%9, i;
    for(i=1; i<10; i++)
    if(a != b);
        printf("a = %d b = %d\n", a, b);
          
    return 0;
}

(A) 5 1

(B) Prints “a = 5 b = 1” ten times.
(C) a = 5 b = 1

(D) The program will not produce any output


Answer: (C)

Explanation: The printf statement is outside the if block because of the semicolon operator after the if statement and thus it is also outside the for loop block. So, it is executed only once.

Quiz of this Question

Last Updated : 28 Aug, 2018
Like Article
Save Article
Similar Reads