Top

Structures, Unions, Enums

41.

Predict the output of above program. Assume that the size of an integer is 4 bytes and size of character is 1 byte. Also assume that there is no alignment needed.

union test
{
    int x;
    char arr[4];
    int y;
};
 
int main()
{
    union test t;
    t.x = 0;
    t.arr[1] = 'G';
    printf("%s", t.arr);
    return 0;
}

 

Answer: A

No answer description available for this question.

Enter details here

42.

Which of the following cannot be a structure member?

Answer: B

No answer description available for this question.

Enter details here

43.

What is the output of this program?

#include 
struct test {
    int x = 0;
    char y = 'A';
};
int main()
{
    struct test t;
    printf("%d, %c", s.x, s.y);
    return 0;
}

 

Answer: B

No answer description available for this question

Enter details here

44.

Enumeration (or enum) is a ______ data type in C?

Answer: A

Enumeration (or enum) is a user defined data type in C. It is mainly used to assign names to integral constants, the names make a program easy to read and maintain.

Enter details here

45.

Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers

Answer: B

No answer description available for this question

Enter details here

46.

What will be the output of the following C code?

#include
enum hi{a,b,c};
enum hello{c,d,e};
main()
{
    enum hi h;
    h=b;
    printf("%d",h);
    return 0;
}

 

Answer: C

The code shown above results in an error: re-declaration of enumerator ‘c’. All enumerator constants should be unique in their scope.

Enter details here

47.

Pick the best statement for the below program:

#include "stdio.h"
 
int main()
{
 union {int i1; int i2;} myVar = {.i2 =100};
 printf("%d %d",myVar.i1, myVar.i2);
 return 0;
}

 

Answer: C

No answer description available for this question.

Enter details here

48.

For the following function call which option is not possible? func(&s.a); //where s is a variable of type struct and a is the member of the struct.

Answer: A

No answer description available for this question

Enter details here

Answer: B

When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum of sizes of its members. The smaller members may end with unused slack bytes. While in case of Union when a variable is associated with a union, the compiler allocates the memory by considering the size of the largest memory. So, size of union is equal to the size of largest member.

Enter details here

50.

#include 

typedef enum{
    Male=-1, Female
}SEX;

int main()
{
  SEX var = Male;
  SEX var1 = Female;
  printf("%d %d",var, var1);
  return 0;

}

 

Answer: A

No answer description available for this que

Enter details here

Loading…
Tags: Structures, Unions, Enums Questions and Answers || Structures, Unions, Enums MCQ Questions and Answers || Structures, Unions, Enums GK Questions and Answers || Structures, Unions, Enums GK MCQ Questions || Structures, Unions, Enums Multiple Choice Questions and Answers || Structures, Unions, Enums GK || GK on Structures, Unions, Enums || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming