ExamVeda
Login
Home
51
Find the output of the following program.
#include<stdio.h>
void main()
{
   int y=10;
   if(y++>9 && y++!=10 && y++>11)
      printf("%d", y);
   else
      printf("%d", y);
}
Discuss
Answer & Solution
Answer: Option C
Solution:
Here if Statement is true and if statement executes left to right. Since its AND operator so all the condition should be check until it finds any false statement. Initially y = 10 In 1st condition: y++>9 which is true and y become 11 in next use. In 2nd condition: y++!=10 which is also true and y become 12 in next use In 3rd condition: y++>11 which is also true and y become 13 in next use After that printf statement will execute and print y = 13
52
What will be the value of sum after the following program is executed?
void main()
{
   int sum=1, index = 9;
   do{
      index = index – 1;
      sum *= 2;
   }while( index > 9 );
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
53
What is the right choice, if the following loop is implemented?
void main()
{
   int num = 0;
   do{
      --num;
      printf("%d", num);
   }while( ++num >= 0 );
}
Discuss
Answer & Solution
Answer: Option D
Solution:

As the value of num is decremented(--num) and again incremented(++num) and hence no change in num and it remains 0 only causing infinite loop.

54
What will be the final value of the digit?
void main()
{
   int digit = 0;
   for( ; digit <= 9; )
   digit++;
   digit  *= 2;
   --digit;
}
Discuss
Answer & Solution
Answer: Option C
Solution:
First of all for loop have no braces so for loop on have only next line in its body.
for( ; digit <= 9; )
digit++;
After completing for loop digit = 10;
next statement digit *= 2; i.e digit = digit * 2 = 20;
next statement digit--; i.e 20-- => 19
So final value of digit is 19
55
What will be the following code's output if choice = 'R'?
switch(choice)
{
   case 'R' : printf("RED");
   case 'W' : printf("WHITE");
   case 'B' : printf("BLUE");
   default  : printf("ERROR");break;
}
Discuss
Answer & Solution
Answer: Option B
Solution:

As the first option is matching, the cases are evaluated till the break statement is encountered or end of switch statement is encountered.

56
Consider the following program fragment:
for(c=1, sum=0; c <= 10; c++)
{
   scanf("%d", &x);
   if( x < 0 ) continue;
   sum += x;
}
What would be the value of sum for the input 1, -1, 2, -2, 3, -3, 4, -4, 5, -5
Discuss
Answer & Solution
Answer: Option E
Solution:

It is summation of 1+2+3+4+5 as continue statement is going to be executed for every input of -1, -2, -3, -4, -5.

57
What will be printed if the following code is executed?
void main()
{
   int x=0;
   for( ; ; )
   {
      if( x++ == 4 ) break;
      continue;
   }
   printf("x=%d", x);
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
58
Consider the following code:
void main()
{
   int a[5] = {6,8,3,9,0}, i=0;
   if(i != 0)
   {
      break;
      printf("%d", a[i]);
   }
   else
      printf("%d", a[i++]);
}

What is the output of the above program?
Discuss
Answer & Solution
Answer: Option D
Solution:

break can't be used with selection control structures, but can used with repetitive(for, while), or select control structure(switch).

59
What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)
#include <stdio.h>
void main()
{
    int ch;
    printf("enter a value between 1 to 2:");
    scanf("%d", &ch);
    switch (ch, ch + 1)
    {
       case 1:
          printf("1\n");
          break;
       case 2:
          printf("2");
          break;
    }
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
60
What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int i = 0;
    do
    {
        printf("Hello");
    } while (i != 0);
}
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board