C Structure 2

include <stdio.h>

int main

{

enum months {JAN=-1, FEB, MARCH=6, APRIL, MAY, JUNE};

printf("%d, %d, %d, %d, %d, %d\n", ++JAN, FEB, MARCH, APRIL, MAY, JUNE);

return 0;

}

Example


- 0, 1, 6, 3, 4, 5

- -1, 0, 1, 2, 3, 4

- 0, 0, 6, 7, 8, 9

- 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?

struct employ

{

int ecode;

struct employ e;

};

Example


- Linked Error

- Error: in structure declaration

- No error

- 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?

include<stdio.h>

int main

{

struct employ

{

char name[22];

int age;

float bs;

};

struct employ e;

e.name = "Nakul";

e.age = 22;

printf("%s %d\n", e.name, e.age);

return 0;

}

Example


- Error: invalid constant expression

- Error: Rvalue required

- Error: Lvalue required/incompatible types in assignment

- 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?

include<stdio.h>

main

{

enum { GREAT, is=7, india };

printf("%d %d", GREAT, india);

}

Example


- Compile error

The correct option is (c).

Explanation:

In an enum data type, the sequence always begins at 0. If a value is explicitly assigned, the sequence then continues from that assigned value onwards.

Therefore 0 8 is the output of the given program.

Input Required

This code uses input(). Please provide values below: