C LANGUAGE MULTIPLE CHOICE QUESTION
Check your Knowledge Press to Start www.prolearninghub.com
1. Which of the following return-type cannot be used for a function in C? char * struct void None of the mentioned www.prolearninghub.com
2. Which of the following is not possible under any scenario? (*s1).number = 10; None of the mentioned www.prolearninghub.com
3. Which of the following operation is illegal in structures? Typecasting of structure Pointer to a variable of same structure Dynamic allocation of memory for structure All of the mentioned www.prolearninghub.com
4. Presence of code like “s.t.b = 10” indicate. Syntax Error Structure double data type An ordinary variable name www.prolearninghub.com
5. The output of the code below is #include <stdio 5. The output of the code below is #include <stdio.h> struct student{ char *name; }; struct student fun(void){ struct student s; s.name = "alan"; return s;} void main(){ struct student m = fun(); s.name = "turing"; printf("%s", m.name);} Alan Compile time error Turing Nothing www.prolearninghub.com
depends on the standard 6. What is the output of this C code? #include <stdio.h> struct point { int x; int y; }; int main() { struct point p = {1}; struct point p1 = {1}; if(p == p1) printf("equal\n"); else printf("not equal\n"); } Compile time error Equal depends on the standard not equal www.prolearninghub.com
7. What is the output of this C code. #include <stdio 7. What is the output of this C code? #include <stdio.h> struct point { in t x; int y; }; struct notpoint { int x; int y; }; struct point foo(); int main() { struct point p = {1}; struct notpoint p1 = {2, 3}; p1 = foo(); printf("%d\n", p1.x); } struct point foo() { struct point temp = {1, 2}; return temp; } compile time error Undefined behavior 1 2 www.prolearninghub.com
8. The correct syntax to access the member of the ith structure in the array of structures is? Assuming: struct temp { int b; }s[50]; s.b.[i]; s.[i].b; s.b[i]; s[i].b; www.prolearninghub.com
9. Comment on the output of this C code. #include <stdio 9. Comment on the output of this C code? #include <stdio.h> struct temp { int a; int b; int c; }; main() { struct temp p[] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; } No Compile time error, generates an array of structure of size 3 Compile time error, illegal assignment to members of structure No Compile time error, generates an array of structure of size 9 Compile time error, illegal declaration of a multidimensional array www.prolearninghub.com
10. Which of the following uses structure? Array of structures Linked Lists All of the mentioned Binary Tree www.prolearninghub.com
11. What is the correct syntax to declare a function foo() which receives an array of structure in function? void foo(struct *var); void foo(struct *var[]); void foo(struct var); None of the mentioned www.prolearninghub.com
Can’t be estimated due to ambiguous initialization of array 12. What is the output of this C code? (Assuming size of int be 4) #include <stdio.h> struct temp { int a; int b; int c; } p[] = {0}; main() { printf("%d", sizeof(p)); } 4 12 16 Can’t be estimated due to ambiguous initialization of array www.prolearninghub.com
13. What is the output of this C code. #include <stdio 13. What is the output of this C code? #include <stdio.h> struct student { char *name; }; struct student s[2]; void main() { s[0].name = "alan"; s[1] = s[0]; printf("%s%s", s[0].name, s[1].name); s[1].name = "turing"; printf("%s%s", s[0].name, s[1].name); } alan alan alan turing alan alan turing turing alan turing alan turing Run time error www.prolearninghub.com
14. Which of the following are incorrect syntax for pointer to structure? (Assuming struct temp{int b;}*my_struct;) *my_struct.b = 10; (*my_struct).b = 10; my_struct->b = 10; Both (a) and (b) www.prolearninghub.com
15. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function? func(&s.a); func(&(s).a); func(&(s.a)); None of the mentioned www.prolearninghub.com
16. Which of the following structure declaration doesn’t require pass-by-reference? struct{int a;}s; main(){} struct temp{int a;}; main(){ struct temp s; } struct temp{int a;}; main(){} struct temp s; None of the mentioned www.prolearninghub.com
17. For the following function call which option is not possible 17. 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 A) Compiler can access entire structure from the function. C) Individual member’s address can be displayed in structure B) Individual member can be passed by reference in a function. Both (b) and (c). www.prolearninghub.com
Output varies with machine 18. Comment on the output of this C code? #include <stdio.h> struct temp { int a; } s; void change(struct temp); main() { s.a = 10; change(s); printf("%d\n", s.a); } void change(struct temp s) { s.a = 1; } Output will be 1 Output will be 10 Output varies with machine Compile time error www.prolearninghub.com
19. What is the output of this C code. #include <stdio 19. What is the output of this C code? #include <stdio.h> struct p { int x; int y; }; int main() { struct p p1[] = {1, 92, 3, 94, 5, 96}; struct p *ptr1 = p1; int x = (sizeof(p1) / 5); if (x == 3) printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x); else printf("false\n"); } Compile time error False Undefined behavior 1 5 www.prolearninghub.com
20. Size of a union is determined by size of the. First member in the union Last member in the union Biggest member in the union Sum of the sizes of all members www.prolearninghub.com
Such declaration are illegal 21. Comment on the following union declaration? #include <stdio.h> union temp { int a; float b; char c; }; union temp s = {1,2.5,’A’}; //REF LINE Which member of the union will be active after REF LINE? A B C Such declaration are illegal www.prolearninghub.com
22. What would be the size of the following union declaration 22.What would be the size of the following union declaration? #include <stdio.h> union uTemp { double a; int b[10]; char c; } u; (Assuming size of double = 8, size of int = 4, size of char = 1) 4 8 40 80 www.prolearninghub.com
23. What type of data is holded by variable u int this C code 23. What type of data is holded by variable u int this C code? #include <stdio.h> union u_tag { int ival; float fval; char *sval; } u; Will be large enough to hold the largest of the three types; Will be large enough to hold the smallest of the three types; Will be large enough to hold the all of the three types; None of the mentioned www.prolearninghub.com
24. Members of a union are accessed as________________. A) union-name.member B) union-pointer->member Both A & B None of the mentioned www.prolearninghub.com
You cannot have union inside structure 25. What is the output of this C code? #include <stdio.h> struct { char *name; union{ char *sval;} u;} symtab[10]; the first character of the string sval by either of A) *symtab[i].u.sval B) symtab[i].u.sval[0] You cannot have union inside structure Both a & b www.prolearninghub.com
26. What is the output of this C code(size of int and float is 4) 26. What is the output of this C code(size of int and float is 4)? #include <stdio.h> union { int ival; float fval; } u; void main() { printf("%d", sizeof(u)); } 16 8 4 32 www.prolearninghub.com
27. What is the output of this C code. #include <stdio 27. What is the output of this C code? #include <stdio.h> union stu { int ival; float fval; }; void main() { union stu r; r.ival = 5; printf("%d", r.ival); } 9 16 5 Compile time error www.prolearninghub.com
28. What is the output of this C code. #include <stdio 28. What is the output of this C code? #include <stdio.h> union { int x; char y; }p; int main() { p.x = 10; printf("%d\n", sizeof(p)); } Compile time error Sizeof(int) + sizeof(char) Depends on the compiler Sizeof(int) www.prolearninghub.com
29. What is the output of this C code. #include <stdio 29. What is the output of this C code? #include <stdio.h> union { int x; char y; }p; int main() { p.x = 10; printf("%d\n", sizeof(p)); } Compile time error Sizeof(int) + sizeof(char) Depends on the compiler Sizeof(int) www.prolearninghub.com
Depends on the compiler 30. What is the output of this C code? #include <stdio.h> union p { int x; char y; }; int main() { union p p, b; p.y = 60; b.x = 12; printf("%d\n", p.y); } Compile time error Depends on the compiler 60 Undefined behaviour www.prolearninghub.com
31. What is the output of this C code. #include <stdio 31. What is the output of this C code? #include <stdio.h> union p { int x; char y; }k = {1, 97}; int main() { printf("%d\n", k.y); } Compile time error 97 A 1 www.prolearninghub.com
Depends on the standard 32. What is the output of this C code? #include <stdio.h> union p { int x; char y; }k = {.y = 97}; int main() { printf("%d\n", k.y); } Compile time error 97 A Depends on the standard www.prolearninghub.com
Implementation dependent 33. What is the output of this C code? #include <stdio.h> union p { int x; float y; }; int main() { union p p, b; p.x = 10; printf("%f\n", p.y); } Compile time error Implementation dependent 10.000000 0.000000 www.prolearninghub.com
34. Which of the following share a similarity in syntax. 1. Union 2 34. Which of the following share a similarity in syntax? 1. Union 2. Structure 3. Arrays 4. Pointers 2 and 4 3 and 4 1 and 3 1 and 2 www.prolearninghub.com
35. What is the output of this C code. #include <stdio 35. What is the output of this C code? #include <stdio.h> union utemp { int a; double b; char c; }u; int main() { u.c = 'A'; u.a = 1; printf("%d", sizeof(u)); } The output will be: (Assuming size of char = 1, int = 4, double = 8) 1 4 6 8 www.prolearninghub.com
36. The address operator &, cannot act on R-value Arithmetic expressions R-value and Arithmetic expressions Local variable www.prolearninghub.com
37. C preprocessor: Takes care of conditional compilation Takes care of macros Takes care of include files All of them www.prolearninghub.com
38. A preprocessor command need not start on a new line Need not start on the first column Has # as the first character Comes before the first executable statement www.prolearninghub.com
39. What will be the output of the program. #include<stdio 39. What will be the output of the program? #include<stdio.h> #define int char void main() { int i = 65; printf("sizeof(i)=%d", sizeof(i)); } sizeof(i)=2 sizeof(i)=1 Compiler Error None of These www.prolearninghub.com
40. What will be the output of the following program? #include<stdio.h> #define square(x) x*x void main() { int i; i = 64/square(4); printf("%d", i); } 4 64 16 None of these www.prolearninghub.com
41. What will be the output of the program code. #include<stdio 41. What will be the output of the program code? #include<stdio.h> #define a 10 void main() { #define a 50 printf("%d", a); } 50 10 Compiler error None of these www.prolearninghub.com
42. Find the output of the following program 42. Find the output of the following program. void main() { printf("%d, %d", sizeof(int *), sizeof(int **)); } 2, 0 2, 2 0, 2 2,4 www.prolearninghub.com
43. Find the output of the following program. void main() { int i=10; /* assume address of i is 0x1234ABCD */ int *ip=&i; int **ipp=&&i; printf("%x,%x,%x", &i, ip, *ipp); } 0x1234ABCD, 0x1234ABCD, 10 0x1234ABCD, 0x1234ABCD, 0x1234ABCD 0x1234ABCD, 10, 10 Syntax error www.prolearninghub.com
44. What is the base data type of a pointer variable by which the memory would be allocated to it? Float No data type Unassigned int www.prolearninghub.com
45. The operator > and < are meaningful when used with pointers, if The pointers point to structure of similar data type. The pointers point to elements of the same array. None of these www.prolearninghub.com
46. The declaration int (*p) [5]; means p is one dimensional array of size 5, of pointers to integers. p is a pointer to a 5 elements integer array The same as int *p[ None of these www.prolearninghub.com
47. #define PI 3.141 Its float Its double There is no type associated with PI, as it’s just a text substitution Syntax error, semi colon is missing with the definition of PI www.prolearninghub.com
48. In DOS, What is the purpose of the function randomize() in Turbo C? Displays a random number generator with a random value based on time Displays a random number Displays a random number generator in the specified range. Invalid function www.prolearninghub.com
49. Predict the data type of the following mathematical operation. 2 int long float double www.prolearninghub.com
50. Which of the following % operation is invalid? 2 % 4; 2 % 4f; 2 % 4l; None www.prolearninghub.com
The Results