Skip to content
Related Articles
Open in App
Not now

Related Articles

Algorithms Quiz | SP2 Contest 1 | Question 1

Improve Article
Save Article
Like Article
  • Last Updated : 28 Aug, 2018
Improve Article
Save Article
Like Article

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

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!