Top

Structures, Unions, Enums

21.

What is the output of this program?

void main()
  {
  struct bitfields {
  int bits_1: 2;
  int bits_2: 9;
  int bits_3: 6;
  int bits_4: 1;
  }bit;
  printf("%d", sizeof(bit));
}

 

Answer: B

 

1 byte = 8 bits In the above program we assign 2, 9, 6, 1 for the variables. Sum of the bits assigned is, 2 + 9 + 6 + 1 = 18, It is greater than 2 bytes, so it automatically takes 3 bytes.

Enter details here

Answer: B

No answer description available for this question

Enter details here

23.

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[8];
    int y;
};
 
int main()
{
    printf("%d", sizeof(union test));
    return 0;
}

 

Answer: C

No answer description available for this question.

Enter details here

24.

What is the output of this program?

#include 
int main(){
    struct leader
 {
 char *lead;
 int born;
 };
 struct leader l1 = {"AbdulKalam", 1931};
 struct leader l2 = l1;
 printf("%s %d", l2.lead, l1.born);
}

 

Answer: C

We can assign one structure member to the another structure member as like normal variable assignmentation. We can access the same values using different structure variables.

Enter details here

25.

What is the output of this program?

#include 
struct employee
{
  char *empname;
  int salary;
};
int main()
{
  struct employee e, e1;
  e.empname = "Sridhar";
  e1 = e;
  printf("%s %s", e.empname, e1.empname);
  return 0;
}

 

Answer: C

No answer description available for this question

Enter details here

Answer: D

No answer description available for this question

Enter details here

Answer: A

No answer description available for this question

Enter details here

28.

#include 

typedef enum{
    Male, Female=0
}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

29.

What is the output of this C code?

#include 
    struct student
    {
        int no;
        char name[20];
    }
    void main()
    {
        struct student s;
        s.no = 8;
        printf("hello");
    }

 

Answer: A

No answer description available for this question.

Enter details here

Answer: A

The statement that two enum symbols cannot have the same value is incorrect. Any number of enum symbols can have the same value.

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