Sail E0 Webinar

MCQs

Total Questions : 66 | Page 3 of 7 pages
Question 21.


Point out the error in the following program.


#include<stdio.h>
struct emp
{
char name[20];
int age;
};
int main()
{
emp int xx;
int a;
printf("%d\n", &a);
return 0;
}
  1.    Error: in printf
  2.    Error: in emp int xx;
  3.    No error.
  4.    None of these
 Discuss Question
Answer: Option B. -> Error: in emp int xx;


There is an error in the line emp int xx;
To overcome this error, remove the int and add the struct at the begining of emp int xx;


#include<stdio.h>
struct emp
{
char name[20];
int age;
};
int main()
{
struct emp xx;
int a;
printf("%d\n", &a);
return 0;
}


Question 22.


Point out the error in the following program.


#include<stdio.h>
int main()
{
void v = 0;
printf("%d", v);
return = 0;
}
  1.    Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.
  2.    Program terminates abnormally.
  3.    No error.
  4.    None of these.
 Discuss Question
Answer: Option A. -> Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.

No answer description available for this question


Question 23.


What will be the output of the program?


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

In case of a conflict between a local variable and global variable, 

the local variable gets priority.


Question 24.


In the following program how long will the for loop get executed?


#include
int main()
{
int i = 5;
for(;scanf("%s", &i); printf("%d\n", i));
return = 0;
}
  1.    The for loop would not get executed at all
  2.    The for loop would get executed only once
  3.    The for loop would get executed 5 times
  4.    The for loop would get executed infinite times
 Discuss Question
Answer: Option D. -> The for loop would get executed infinite times

During the for loop execution scanf() ask input and then printf() prints that given input. 

This process will be continued repeatedly because, scanf() returns the number of input 

given, the condition is always true(user gives a input means it reurns '1').

Hence this for loop would get executed infinite times


Question 25.


Point out the error in the following program (if it is compiled with Turbo C compiler).


#include&lt;stdio.h.&gt;
int main()
{
display();
return 0;
}
void display()
{
printf("Placementadda.com");
}
  1.    No error
  2.    display() doesn't get invoked
  3.    display() is called before it is defined
  4.    None of these
 Discuss Question
Answer: Option C. -> display() is called before it is defined


In this program the compiler will not know that the function display() exists.
So, the compiler will generate "Type mismatch in redeclaration of function
display()".
To over come this error, we have to add function prototype of function display().
Another way to overcome this error is to define the function display() before the
int main(); function.


#include<stdio.h>
void display(); /* function prototype */
int main()
{
display();
return 0;
}
void display()
{
printf("Placementadda.com");
}


Question 26.


What is the output of the program?


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0] = 3;
u.ch[1] = 2;
printf("%d, %d, %d\n",u.ch[0], u.ch[1], u.1);
return 0;
}
  1.    3, 2, 515
  2.    515, 2, 3
  3.    3, 2, 5
  4.    None of these
 Discuss Question
Answer: Option A. -> 3, 2, 515

printf("%d, %d, %d`setminus`n", u.ch[0], u.ch[1], u.i); It prints the value of u.ch[0] = 3, 

u.ch[1] = 2 and it prints the value of u.i means the value of entire union size.

What Is The Output Of The Program?#include<stdio.h>int...

So the output is 3, 2, 515


Question 27.


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 28.


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.    4
  5.    Compile Error
 Discuss Question
Answer: Option E. -> Compile Error

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


Question 29.


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 30.


What will be the output of the program?


#include<stdio.h>
nt 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.


Latest Videos

Latest Test Papers