C Programming Structures, Unions, Enums Online Test
Finish Quiz
0 of 30 questions completed
Questions:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
Information
C Programming Structures, Unions, Enums Online Test. C Programming Question and Answers in English. C Programming Structures, Unions, Enums Online mock test paper is free for all students and Very Helpful for Exam Preparation. C Programming Structures, Unions, Enums Online Quiz. C Programming Online Mock test for Structures, Unions, Enums Topic. Here we are providing C Programming Structures, Unions, Enums Online Test Series in English. Check C Programming Mock Test Series 2019-2019.
This paper has 30 questions.
Time allowed is 30 minutes.
The C Programming online Mock Test Exam is Very helpful for all students. Now Scroll down below n click on “Start Quiz” or “Start Test” and Test yourself.
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading...
You must sign in or sign up to start the quiz.
You have to finish following quiz, to start this quiz:
Results
0 of 30 questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 points, (0)
Average score |
|
Your score |
|
Categories
- Not categorized 0%
Pos. | Name | Entered on | Points | Result |
---|---|---|---|---|
Table is loading | ||||
No data available | ||||
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- Answered
- Review
-
Question 1 of 30
1. Question
How will you free the allocated memory ?
Correct
Incorrect
-
Question 2 of 30
2. Question
What is the similarity between a structure, union and enumeration?
Correct
Incorrect
-
Question 3 of 30
3. Question
What will be the output of the program ?
#include
int main() { union var { int a, b; }; union var v; v.a=10; v.b=20; printf("%d\n", v.a); return 0; } Correct
Incorrect
-
Question 4 of 30
4. Question
What will be the output of the program ?
#include
int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit={1, 2, 13}; printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4); return 0; } Correct
Note the below statement inside the struct:
int bit1:1; –> ‘int’ indicates that it is a SIGNED integer.
For signed integers the leftmost bit will be taken for +/- sign.
If you store 1 in 1-bit field:
The left most bit is 1, so the system will treat the value as negative number.
The 2’s complement method is used by the system to handle the negative values.
Therefore, the data stored is 1. The 2’s complement of 1 is also 1 (negative).
Therefore -1 is printed.
If you store 2 in 4-bits field:
Binary 2: 0010 (left most bit is 0, so system will treat it as positive value)
0010 is 2
Therefore 2 is printed.
If you store 13 in 4-bits field:
Binary 13: 1101 (left most bit is 1, so system will treat it as negative value)
Find 2’s complement of 1101:
1’s complement of 1101 : 0010
2’s complement of 1101 : 0011 (Add 1 to the result of 1’s complement)0011 is 3 (but negative value)
Therefore -3 is printed.
Incorrect
Note the below statement inside the struct:
int bit1:1; –> ‘int’ indicates that it is a SIGNED integer.
For signed integers the leftmost bit will be taken for +/- sign.
If you store 1 in 1-bit field:
The left most bit is 1, so the system will treat the value as negative number.
The 2’s complement method is used by the system to handle the negative values.
Therefore, the data stored is 1. The 2’s complement of 1 is also 1 (negative).
Therefore -1 is printed.
If you store 2 in 4-bits field:
Binary 2: 0010 (left most bit is 0, so system will treat it as positive value)
0010 is 2
Therefore 2 is printed.
If you store 13 in 4-bits field:
Binary 13: 1101 (left most bit is 1, so system will treat it as negative value)
Find 2’s complement of 1101:
1’s complement of 1101 : 0010
2’s complement of 1101 : 0011 (Add 1 to the result of 1’s complement)0011 is 3 (but negative value)
Therefore -3 is printed.
-
Question 5 of 30
5. Question
What will be the output of the program in 16 bit platform (Turbo C under DOS) ?
#include
int main() { struct value { int bit1:1; int bit3:4; int bit4:4; }bit; printf("%d\n", sizeof(bit)); return 0; } Correct
Since C is a compiler dependent language, in Turbo C (DOS) the output will be 2, but in GCC (Linux) the output will be 4.
Incorrect
Since C is a compiler dependent language, in Turbo C (DOS) the output will be 2, but in GCC (Linux) the output will be 4.
-
Question 6 of 30
6. Question
What will be the output of the program ?
#include
int main() { enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT); return 0; } Correct
Incorrect
-
Question 7 of 30
7. Question
What will be the output of the program ?
#include
int main() { enum status {pass, fail, absent}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = absent; stud3 = fail; printf("%d %d %d\n", stud1, stud2, stud3); return 0; } Correct
Incorrect
-
Question 8 of 30
8. Question
What will be the output of the program ?
#include
int main() { int i=4, j=8; printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j); return 0; } Correct
Incorrect
-
Question 9 of 30
9. Question
What will be the output of the program in Turbo C (under DOS)?
#include
int main() { struct emp { char *n; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; strupr(e2.n); printf("%s\n", e1.n); return 0; } Correct
Incorrect
-
Question 10 of 30
10. Question
What will be the output of the program in 16-bit platform (under DOS)?
#include
Correct
Incorrect
-
Question 11 of 30
11. Question
What will be the output of the program ?
#include
int main() { struct byte { int one:1; }; struct byte var = {1}; printf("%d\n", var.one); return 0; } Correct
Incorrect
-
Question 12 of 30
12. Question
What will be the output of the program ?
#include
int main() { enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT); return 0; } Correct
Because ++ or — cannot be done on enum value.Incorrect
Because ++ or — cannot be done on enum value. -
Question 13 of 30
13. Question
What will be the output of the program ?
#include
struct course { int courseno; char coursename[25]; }; int main() { struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} }; printf("%d ", c[1].courseno); printf("%s\n", (*(c+2)).coursename); return 0; } Correct
Incorrect
-
Question 14 of 30
14. Question
What will be the output of the program given below in 16-bit platform ?
#include
int main() { enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var; printf("%d\n", sizeof(var)); return 0; } Correct
Incorrect
-
Question 15 of 30
15. Question
Point out the error in the program?
struct emp { int ecode; struct emp *e; };
Correct
This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp.Incorrect
This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp. -
Question 16 of 30
16. Question
Point out the error in the program?
typedef struct data mystruct; struct data { int x; mystruct *b; };
Correct
Here the type name mystruct is known at the point of declaring the structure, as it is already defined.Incorrect
Here the type name mystruct is known at the point of declaring the structure, as it is already defined. -
Question 17 of 30
17. Question
Point out the error in the program?
#include
int main() { struct a { float category:5; char scheme:4; }; printf("size=%d", sizeof(struct a)); return 0; } Correct
Bit field type must be signed int or unsigned int.
The char type: char scheme:4; is also a valid statement.
Incorrect
Bit field type must be signed int or unsigned int.
The char type: char scheme:4; is also a valid statement.
-
Question 18 of 30
18. Question
Point out the error in the program?
struct emp { int ecode; struct emp e; };
Correct
The structure emp contains a member e of the same type.(i.e) struct emp. At this stage compiler does not know the size of sttructure.Incorrect
The structure emp contains a member e of the same type.(i.e) struct emp. At this stage compiler does not know the size of sttructure. -
Question 19 of 30
19. Question
Point out the error in the program?
#include
int main() { struct emp { char name[20]; float sal; }; struct emp e[10]; int i; for(i=0; i9; i++) scanf("%s %f", e[i].name, &e[i].sal); return 0; } Correct
At run time it will show an error then program will be terminated.
Sample output: Turbo C (Windows)
c:\>myprogram
Sample
12.123scanf : floating point formats not linked
Abnormal program terminationIncorrect
At run time it will show an error then program will be terminated.
Sample output: Turbo C (Windows)
c:\>myprogram
Sample
12.123scanf : floating point formats not linked
Abnormal program termination -
Question 20 of 30
20. Question
Point out the error in the program?
#include
#include void modify(struct emp*); struct emp { char name[20]; int age; }; int main() { struct emp e = {"Sanjay", 35}; modify(&e); printf("%s %d", e.name, e.age); return 0; } void modify(struct emp *p) { p ->age=p->age+2; } Correct
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.Incorrect
The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype. -
Question 21 of 30
21. Question
Point out the error in the program in 16-bit platform?
#include
int main() { struct bits { int i:40; }bit; printf("%d\n", sizeof(bit)); return 0; } Correct
Incorrect
-
Question 22 of 30
22. Question
Point out the error in the program?
#include
int main() { union a { int i; char ch[2]; }; union a z1 = {512}; union a z2 = {0, 2}; return 0; } Correct
Incorrect
-
Question 23 of 30
23. Question
Point out the error in the program?
#include
int main() { struct emp { char n[20]; int age; }; struct emp e1 = {"Dravid", 23}; struct emp e2 = e1; if(e1 == e2) printf("The structure are equal"); return 0; } Correct
Incorrect
-
Question 24 of 30
24. Question
Point out the error in the program?
#include
int main() { struct bits { float f:2; }bit; printf("%d\n", sizeof(bit)); return 0; } Correct
Incorrect
-
Question 25 of 30
25. Question
Point out the error in the program?
#include
int main() { struct emp { char name[25]; int age; float bs; }; struct emp e; e.name = "Suresh"; e.age = 25; printf("%s %d\n", e.name, e.age); return 0; } Correct
We cannot assign a string to a struct variable like e.name = “Suresh”; in C.
We have to use strcpy(char *dest, const char *source) function to assign a string.
Ex: strcpy(e.name, “Suresh”);
Incorrect
We cannot assign a string to a struct variable like e.name = “Suresh”; in C.
We have to use strcpy(char *dest, const char *source) function to assign a string.
Ex: strcpy(e.name, “Suresh”);
-
Question 26 of 30
26. Question
Which of the following statements correct about the below program?
#include
int main() { struct emp { char name[25]; int age; float sal; }; struct emp e[2]; int i=0; for(i=0; i2; i++) scanf("%s %d %f", e[i].name, &e[i].age, &e[i].sal); for(i=0; i2; i++) scanf("%s %d %f", e[i].name, e[i].age, e[i].sal); return 0; } Correct
Incorrect
-
Question 27 of 30
27. Question
Which of the following statements correct about the below program?
#include
int main() { union a { int i; char ch[2]; }; union a u1 = {512}; union a u2 = {0, 2}; return 0; } 1: u2 CANNOT be initialized as shown.
2: u1 can be initialized as shown.
3: To initialize char ch[] of u2 ‘.’ operator should be used.
4: The code causes an error ‘Declaration syntax error’Correct
Incorrect
-
Question 28 of 30
28. Question
Which of the following statements correctly assigns 12 to month using pointer variable pdt?
#include
struct date { int day; int month; int year; }; int main() { struct date d; struct date *pdt; pdt = &d; return 0; } Correct
Incorrect
-
Question 29 of 30
29. Question
A union cannot be nested in a structure
Correct
Incorrect
-
Question 30 of 30
30. Question
Nested unions are allowed
Correct
Incorrect
very good