Control Instructions

26

What will be the output of the program?

#include<stdio.h>
int main()
{
    char j=1;
    while(j < 5)
    {
        printf("%d, ", j);
        j = j+1;
    }
    printf("\n");
    return 0;
}

A. 1 2 3 ... 127
B. 1 2 3 ... 255
C. 1 2 3 ... 127 128 0 1 2 3 ... infinite times
D. 1, 2, 3, 4

27

What will be the output of the program?

#include<stdio.h>
int main()
{
    int  i = 1;
    switch(i) 
    {
        printf("Hello\n');
        case 1:
            printf("Hi\n");
            break;
        case 2:
            printf("\nBye\n");
            break;
    }
    return 0;
}
A. Hello Hi
B. Hello Bye
C. Hi
D. Bye

28


#include<stdio.h>
int main()
{
    int i=4;
    switch(i)
    {
        default:
           printf("This is default\n");
        case 1:
           printf("This is case 1\n");
           break;
        case 2:
           printf("This is case 2\n");
           break;
        case 3:
           printf("This is case 3\n");
    }
    return 0;
}
A. This is default This is case 1
B. This is case 3 This is default
C. This is case 1 This is case 3
D. This is default

29

What will be the output of the program?

#include<stdio.h>
int main()
{
    int x = 10, y = 20;
    if(!(!x) && x)
        printf("x = %d\n", x);
    else
        printf("y = %d\n", y);
    return 0;
}
What will be the output of the program?
A. y =20
B. x = 0
C. x = 10
D. x = 1

30

What will be the output of the program?

#include<stdio.h>
int main()
{
    int i=3;
    switch(i)
    {
        case 1:
            printf("Hello\n");
        case 2:
            printf("Hi\n");
        case 3:
            continue;
        default:
            printf("Bye\n");
    }
    return 0;
}
A. Error: Misplaced continue
B. Bye
C. No output
D. Hello Hi