Javatpoint Logo
Javatpoint Logo

C Structure, Union, Enums Test 2


6) What will be the output of the below program?

  1. 3, 2, 5
  2. 515, 515, 4
  3. 3, 2, 515
  4. 515, 2, 3

The correct option is (c).

Explanation:

In a program system will allocate 2 bytes for the union.

The statements un.ch[0]=3; un.ch[1]=2; store the data in memory.

Therefore the output of program is 3, 2, 515.


7) What will be the output of the below program?

  1. 0, 1, 6, 3, 4, 5
  2. -1, 0, 1, 2, 3, 4
  3. 0, 0, 6, 7, 8, 9
  4. Compile Error

The correct option is (d).

Explanation:

Increment and decrement operations are not allowed to be performed in user defined data type.

Since enum is a user defined data type, no operations can be performed on user-defined data types.

Therefore ++ or -- logical operations cannot be done on enum value and the program will return compile error in the output on using this operations in enum data type.


8) Find out the error in the below program?

  1. Linked Error
  2. Error: in structure declaration
  3. No error
  4. None of the above

The correct option is (b).

Explanation:

The structure employ contains a member 'e' of a same data type i.e. struct employ.

In this stage the compiler does not know the size of structure.

Therefore the compiler returns Error: in structure declaration.


9) Find out the error in the below program?

  1. Error: invalid constant expression
  2. Error: Rvalue required
  3. Error: Lvalue required/incompatible types in assignment
  4. No error, Output: Nakul 22

The correct option is (c).

Explanation:

In program we assign string to a struct variable like e.name = "Nakul";

In C programming language we are not allowed to assign a string to struct variable.

We have to use strcpy(char *dest, const char *source) function for assigning a string

For example: strcpy(e.name, "Nakul");

Therefore the compiler returns Error: Lvalue required/incompatible types in assignment


10) What will be the output of the below program?

  1. 0 1
  2. 0 2
  3. 0 8
  4. Compile error

The correct option is (c).

Explanation:

In enum data type sequence always start with 0. If the value is assigned then sequence continues from the assigned value.

Therefore 0 8 is the output of the given program.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA