Sail E0 Webinar

MCQs

Total Questions : 35 | Page 4 of 4 pages
Question 31.


What would be the output of the following program ?


#include<stdio.h>
int main()
{
static int a[20];
int i = 0;
a[i] = i ;
printf("%d, %d, %d\n", a[0], a[1], i);
return 0;
}
  1.    1,0,1
  2.    1,1,1
  3.    0,0,0
  4.    0,1,0
 Discuss Question
Answer: Option C. -> 0,0,0


Step 1: static int a[20]; here variable a is declared as an integer type and static. If a variable is declared as static and it will ne automatically initialized to value '0'(zero).


Step 2: int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero).
Step 3: a[i] = i ; becomes a[0] = 0;
Step 4: printf("%d, %d, %d`setminus`n", a[0], a[1], i);
Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0.
Step 4: Hence the output is "0, 0, 0".



Question 32.


What will be the output of the program ?


#include<stdio.h>
int main()
{
int i=2;
printf("%d, %d\n", ++i, ++i);
return 0;
}
  1.    3, 4
  2.    4, 3
  3.    4, 4
  4.    Output may vary from compiler to compiler
 Discuss Question
Answer: Option D. -> Output may vary from compiler to compiler

The order of evaluation of arguments passed to a function call is unspecified.



Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.


In TurboC, the output will be 4, 3.


In GCC, the output will be 4, 4.



Question 33.

Are the following two statements same ?



a<=20?b=30:c=30;
(a<=20)?b:c=30;


  1.    yes
  2.    no
 Discuss Question
Answer: Option B. -> no


Question 34.

What will be the output of the program ?


#include<stdio.h>
int main()
{
int x=10,y=20,z=5,i;
i=x<y<z;
printf("%d\n",i);
return 0;
}


  1.    1
  2.    0
  3.    Error
  4.    None of these
 Discuss Question
Answer: Option A. -> 1


Question 35.
Which of the following are unary operators in C?
1.    !
2.    sizeof
3.    ~
4.    &&
  1.    1,2
  2.    2,3
  3.    2,4
  4.    1,2,3
 Discuss Question
Answer: Option D. -> 1,2,3

An operation with only one operand is called unary operation.
Unary operators:
! Logical NOT operator.
~ bitwise NOT operator.
sizeof Size-of operator.


&& Logical AND is a logical operator.


Therefore, 1, 2, 3 are unary operators.



Latest Videos

Latest Test Papers