Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

Algorithms Quiz | SP2 Contest 1 | Question 1

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Predict the output of below C program:

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

My Personal Notes arrow_drop_up
Last Updated : 28 Aug, 2018
Like Article
Save Article
Similar Reads