Sail E0 Webinar

MCQs

Total Questions : 72 | Page 1 of 8 pages
Question 1.


If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide
then will the following structure always occupy 7 bytes?


struct ex
{
char ch;
int i;
long int a;
};
  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

A compiler may leave holes in structures by padding the first char in the structure with another 

byte just to ensures that the integer that follows is stored at an location. Also, there might be 

2extra bytes after the integer to ensure that the long integer is stored at an address, which is 

multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.


Question 2.

Can a structure can point to itself?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes

A structure pointing to itself is called self-referential structures.
Question 3.


Will the following declaration work?


typedef struct s
{
int a;
float b;
}s;
  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes

No answer description available for this question. 


Question 4.

Can we have an array of bit fields?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

No answer description available for this question. 


Question 5.

Is it necessary that the size of all elements in a union should be same?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

No answer description available for this question. 


Question 6.

By default structure variable will be of auto storage class


  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes

No answer description available for this question. 


Question 7.

The elements of union are always accessed using & operator


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

No answer description available for this question. 


Question 8.

A pointer union CANNOT be created


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

No answer description available for this question. 


Question 9.

Is there easy way to print enumeration values symbolically?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

You can write a function of your own to map an enumeration constant to a string.


Question 10.


Will the following code work?


#include<stdio.h>
#include<malloc.h>
struct emp
{
int len;
char name[1];
};
int main()
{
char newname[] = "Rahul";
struct emp *p = (struct emp *) malloc(sizeof(struct emp) -1 +
strlen(newname)+1);
p->len = strlen(newname);
strcpy(p -> name, newname);
printf("%d %s\n", p->len, p->name);
return 0;
}
  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes

The program allocates space for the structure with the size adjusted so that the 

name field can hold the requested name.


Latest Videos

Latest Test Papers