Control Instructions - Programming

Q1:

What will be the output of the program?
#include<stdio.h>
int main()
{
    int a = 300, b, c;
    if(a >= 400)
        b = 300;
    c = 200;
    printf('%d, %d, %d\n', a, b, c);
    return 0;
}

A 300, 300, 200

B Garbage, 300, 200

C 300, Garbage, 200

D 300, 300, Garbage

ANS:A - 300, 300, 200

Step 1: int a = 300, b, c; here variable a is initialized to '300', variable b and c are declared, but not initialized.
Step 2: if(a >= 400) means if(300 >= 400). Hence this condition will be failed.
Step 3: c = 200; here variable c is initialized to '200'.
Step 4: printf('%d, %d, %d\n', a, b, c); It prints '300, garbage value, 200'. because variable b is not initialized.