Sail E0 Webinar

MCQs

Total Questions : 72 | Page 3 of 8 pages
Question 21.

Nested unions are allowed


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

No answer description available for this question. 


Question 22.


Which of the following statements correct about the below program?


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u1 = {512};
union a u2 = {0, 2};
return 0;
}

  1.  u2 CANNOT be initialized as shown.
  2.  u1 can be initialized as shown. 
  3. To initialize char ch[] of u2 '.' operator should be used.
  4. The code causes an error 'Declaration syntax error'


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

No answer description available for this question. 


Question 23.


Which of the following statements correctly assigns 12 to month using pointer variable pdt?


#include<stdio.h>
struct date
{
int day;
int month;
int year;
};
int main()
{
struct date d;
struct date *pdt;
pdt = &d;
return 0;
}
  1.    pdt.month = 12
  2.    &pdt.month = 12
  3.    d.month = 12
  4.    pdt->month = 12
 Discuss Question
Answer: Option A. -> pdt.month = 12


Question 24.

A union cannot be nested in a structure


  1.    True
  2.    False
 Discuss Question
Answer: Option B. -> False

No answer description available for this question. 


Question 25.

Which of the following statements correct about the below code?
maruti.engine.bolts=25;


  1.    Structure bolts is nested within structure engine.
  2.    Structure engine is nested within structure maruti.
  3.    Structure maruti is nested within structure engine.
  4.    Structure maruti is nested within structure bolts.
 Discuss Question
Answer: Option B. -> Structure engine is nested within structure maruti.


Question 26.


Which of the following statements correct about the below program?


#include<stdio.h>
int main()
struct emp
{
char name[25];
int age;
float sa1;
};
struct emp e [2];
int i=0;
for(i=0; i<2; i++)
scanf("%s %d %f" , e[i].name, &e[i].age, &e[i].sa1);
for(i=0; i<2; i++)
scanf("%s %d %f" , e[i].name, e[i].age, e[i].sa1);
return 0;
}
  1.    Error: scanf() function cannot be used for structures elements.
  2.    The code runs successfully.
  3.    Error: Floating point formats not linked Abnormal program termination.
  4.    Error: structure variable must be initialized.
 Discuss Question
Answer: Option C. -> Error: Floating point formats not linked Abnormal program termination.


Question 27.


Point out the error in the program?


#include<stdio.h>
int main()
{
struct bits
{
float f:2;
}bit;
printf("%d\n" , sizeof(bit));
return 0;
}
  1.    4
  2.    2
  3.    Error: cannot set bit field for float
  4.    Error: Invalid member access in structure
 Discuss Question
Answer: Option C. -> Error: cannot set bit field for float

No answer description available for this question. 


Question 28.


Point out the error in the program?


#include<stdio.h>
int main()
{
struct emp
{
char n[20];
int age;
};
struct emp e1 = {"Dravid" , 23};
struct emp e2 = e1;
if(e1 == e2)
printf("The structure are are equal");
return 0;
}
  1.    Prints: The structure are equal
  2.    Error: Structure cannot be compared using '=='
  3.    No output
  4.    None of above
 Discuss Question
Answer: Option B. -> Error: Structure cannot be compared using '=='

No answer description available for this question. 


Question 29.


Point out the error in the program?


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a z1 = {512};
union a z2 = {0, 2};
return 0;
}
  1.    Error: invalid union declaration
  2.    Error: in Initializing z2
  3.    No error
  4.    None of above
 Discuss Question
Answer: Option B. -> Error: in Initializing z2

No answer description available for this question. 


Question 30.


Point out the error in the program?


#includ<stdio.h>
int main()
{
struct emp
{
char name[25];
int age;
float bs;
};
struct emp e;
e.name = "Suresh";
e.age = 25;
printf("%s %d\n", e.name, e.age);
return 0;
}
  1.    Error: Lvalue required/incompatible types in assignment
  2.    Error: invalid constant expression
  3.    Error: Rvalue required
  4.    No error, Output: Suresh 25
 Discuss Question
Answer: Option A. -> Error: Lvalue required/incompatible types in assignment

We cannot assign a string to a struct variable like e.name = "Suresh"; in C.

We have to use strcpy(char *dest, const char *source) function to assign a string. 
Ex: strcpy(e.name, "Suresh");


Latest Videos

Latest Test Papers