Programming for Problem Solving (3110003) MCQs

MCQs of Control structure in C

Showing 11 to 20 out of 41 Questions
11.

What is the output?

void main()
{
if(-100)
 printf("Negative number");
else
 printf("Positive number");
}

(a) Positive number
(b) Negative number
(c) Error
(d) Random Behavior
Answer:

Option (b)

12.
What is the output?

void main()
{
 if(1 || 0)
  printf("C Programming");
 else
  printf("learn C");
}

(a) learn C
(b) Compile Error
(c) C Programming
(d) Error
Answer:

Option (c)

13.
What is the output?

void main()
{
 int x= 5;
 if(x < 1);
  printf("Hello");
  printf("Hi");
}

(a) Hi
(b) HelloHi
(c) Error
(d) None of these
Answer:

Option (b)

14.
What is the output?

void main()
{
 int x = 5;
 if (x < 1)
  printf("hello");
 if (x == 5)
  printf("hi");
 else
  printf("no");
}

(a) hi
(b) hello
(c) no
(d) error
Answer:

Option (a)

15.
What is the output?

void main()
{
 int x = 5;
 if (true);
  printf("hello");
}

(a) hello
(b) Error
(c) Blank
(d) None of these
Answer:

Option (a)

16.
What is the output?

void main()
{
 int x = 0;
 if (x == 0)
  printf("hi");
 else
  printf("how are u");
  printf("hello");
}

(a) hi
(b) how are you
(c) hello
(d) hihello
Answer:

Option (d)

17.
If switch case is used, then
(a) Default case must be present
(b) Default case, if used, should not be the last case
(c) Default case, if used, should be the last case
(d) None of these
Answer:

Option (c)

18.
What is the output?

void main()
{
    int ch;
    printf("enter a value between 1 to 2:");
    scanf("%d", &ch);
    switch (ch)
    {
       case 1:
       printf("1\n");
       default:
       printf("2\n");
    }
}
//1 is input

(a) 1
(b) 1 2
(c) 2
(d) Error
Answer:

Option (b)

19.
What is the output?

void main()
{
    int ch;
    printf("enter a value between 1 to 2:");
    scanf("%d", &ch);
    switch (ch)
    {
        case 1:
        printf("1\n");
        break;
        printf("Hi");
        default:
        printf("2\n");
    }
}
//2 is input

(a) 1
(b) Hi 2
(c) 2
(d) Error
Answer:

Option (c)

20.
What is the output?

void main()
{
    int x = 0;
    if (x++)
        printf("true\n");
    else if (x == 1)
        printf("false\n");
}

(a) true
(b) false
(c) blank
(d) Error
Answer:

Option (b)

Showing 11 to 20 out of 41 Questions