Sail E0 Webinar

MCQs

Total Questions : 66 | Page 6 of 7 pages
Question 51.


What is the output of the program



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

When an automatic array is partially initialized, the remaining elements are initialized to 0.


Question 52.

What is the output of the program in Turbo C (in DOS 16-bit OS)?

#include<stdio.h>
int main()
{
char *s1;
char far *s2;
printf("%d, %d, %d\n", sizeof(s1), sizeof(s2));
return 0;
}


  1.    2 4
  2.    4 2
  3.    2 2
  4.    4 4
 Discuss Question
Answer: Option A. -> 2 4


Any pointer size is 2 bytes. (only 16-bit offset)
So, char *s1 = 2 bytes.
So, char far *s2 = 4 bytes.


A far pointer has two parts: a 16-bit segment value and a 16-bit offset value.


Since C is a compiler dependent language, it may give different
output in other platforms. The above program works fine in Windows
(TurboC), but error in Linux (GCC Compiler).



Question 53.

What is the output of the program ?


#include<stdio.h>
int main()
{
extern int fun(float);
int a;
a = fun(3.14);
printf("%d\n", a);
return 0;
}
int fun(int aa)
{
return (int)++aa;
}


  1.    3
  2.    3.14
  3.    0
  4.    Compile Error
 Discuss Question
Answer: Option D. -> Compile Error

2 Errors
1. Type mismatch in redeclaration of fun
2. Type mismatch in parameter aa



Question 54.

What is 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.    0
  2.    1
  3.    Error
  4.    None of these
 Discuss Question
Answer: Option B. -> 1

Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The 1 is assigned to i.


Question 55.

What would be the output of the following program ?



#include<stdio.h>
int X=40;
int main()
{
int X=20;
printf("%d\n", X);
return 0;
}


  1.    20
  2.    40
  3.    Error
  4.    No output
 Discuss Question
Answer: Option A. -> 20

Whenever there is conflict between a local variable and global variable, the local variable gets priority.


Question 56.


Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ?



  1.    rem = 3.14 % 2.1;
  2.    rem = modf(3.14, 2.1);
  3.    rem = fmod(3.14, 2.1);
  4.    Remainder cannot be obtain in floating point division.
 Discuss Question
Answer: Option C. -> rem = fmod(3.14, 2.1);

fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point divisions.


#include <stdio.h>
#include <math.h>
int main ()
{
printf ("fmod of 3.14/2.1 is %lfn", fmod (3.14,2.1) );
return 0;
}


Output:
fmod of 3.14/2.1 is 1.040000


Question 57.

In the following program where is the variable a getting defined and where is it getting declared ?


#include<stdio.h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;


  1.    extern int a : Declaration, extern int a : Defined
  2.    int a = 20 : Declaration, extern int a : Defined
  3.    extern int a : Declaration, int a = 20 : Defined
  4.    int a = 20 : Declaration, int a = 20 : Defined
 Discuss Question
Answer: Option C. -> extern int a : Declaration, int a = 20 : Defined

extern int a is the declaration whereas int a = 20 is the definition



Question 58.

What would be the output of the following program ?


#include<stdio.h>
int X=40;
int main()
{
int X=40;
{
int X=20;
printf("\n%d", X);
}
printf("%d", X);
return 0;
}
  1.    40 20
  2.    20 40
  3.    40 40
  4.    20 20
 Discuss Question
Answer: Option B. -> 20 40

In case of conflict between local variables the one which is more local gets the priority.



Question 59.

What is the output of:


#include<stdio.h>
main()
{
int a, b;
a = -3 - - 3 ;
b = -3 - - ( - 3 ) ;
printf("a = %d b = %d",a,b);
}
  1.    -3 3
  2.    -6 0
  3.    0 -6
  4.    None of the Above
 Discuss Question
Answer: Option C. -> 0 -6

-3 - -3= -3 + 3 = 0
-3 --(-3)= -3 - 3 = -6


Question 60.

What would be the output of the program in 16 bit platform (Turbo C under DOS)?


#include<stdio.h>
int main()
{
extern int a;
printf("\n%d",a);
return 0;
}
int a = 20;
  1.    20
  2.    0
  3.    Garbage Value
  4.    Error
 Discuss Question
Answer: Option A. -> 20


Latest Videos

Latest Test Papers