ExamVeda
Login
Home
41
What will be the output of given program?
#include<stdio.h>
void main()
{
	int a=1;
	if("%d=hello", a);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

the if is conditional and it checks for expression whether it is zero or non-zero so it doesn't print any data it is clear and it is clearly seen that there is not a single syntax error therefore no complier error.
After compling the program will be executed but there is not a single printf statement so it is executed but will not give any output.

42
What will be the output of given program?
#include<stdio.h>
void main()
{
	int a=3;
	for(;a;printf("%d ", a--);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Decrement operator in for loop statement are executed until the condition is true.
So it is executed till "a" not equal to zero and printf statement inside for loop print a value of "a"

43
What will be the output of given program?
#include<stdio.h>
void main()
{
      int i=1, j=-1;
      if((printf("%d", i)) < (printf("%d", j))) 
            printf("%d", i);
      else 
            printf("%d", j);
}
Discuss
Answer & Solution
Answer: Option A
Solution:
Here if statement is executed since we know that printf() function return the number of character print.
Here printf("%d", i) return 2 because it print 1 and newline i.e 2.
And, printf("%d', j) return 3 because it print -1 and newline i.e number of character is 3.
Therefore if statement look like if(2<3) yes its true.
So if statement will execute. And answer is 1 -1 1.
44
What will be the output of the following piece of code?
for(i = 0; i<10; i++);
printf("%d", i);
Discuss
Answer & Solution
Answer: Option A
Solution:

Due to semicolon(;) at the end of the for loop, after 10 iterations for loop will be terminated and the result will be 10.

45
What will be the output of the following code?
#include<stdio.h>
void main()
{
    int s=0;
    while(s++<10)
    {
        if(s<4 && s<9)
        continue;
        printf("%dt", s);
    }
}
Discuss
Answer & Solution
Answer: Option C
Solution:
'If' statement only true when value of 's' is less then 4

Control Structures mcq solution image

46
Which command is used to skip the rest of a loop and carry on from the top of the loop again?
Discuss
Answer & Solution
Answer: Option C
Solution:
Syntax: continue ;

Causes control to pass to the end of the innermost enclosing while, do, or for statement, at that point the loop continuation condition is re-evaluated. Example:
for(i = 0; i < 20; i++){
   if(array[i] == 0)
      continue;
   array[i] = 1/array[i];
}
47
What is the output of the following program?
#include<stdio.h>
int c[10] = {1,2,3,4,5,6,7,8,9,10};   
main()
{
   int a, b=0;
   for(a=0;a<10;++a)
      if(c[a]%2 == 1)
         b+=c[a];
   printf("%d", b);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Condition if(c[a]%2 == 1) forces only odd numbers to add in the sum.

48
What is the output of the following statements?
for(i=10; i++; i<15)
   printf("%d ", i);
Discuss
Answer & Solution
Answer: Option D
Solution:

Since the condition is always true it will go to infinite loop.

49
The type of the controlling expression of a switch statement cannot be of the type ........
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
50
What's wrong in the following statement, provided k is a variable of type int?
for(k = 2, k <=12, k++)
Discuss
Answer & Solution
Answer: Option E
Solution:

In for loop the three statements parts are separated by two semicolons which are missing here.