💡 C Programming MCQs and Exam Questions

Practice 159 approved 💡 C Programming MCQs and exam questions from the 💻 Programming subject.

159 solved MCQs

What is (void*)0?Answer: Representation of NULL pointer Can you combine the following two statements into one? char *p; p = (char*) malloc(100);Answer: char *p = (char*)malloc(100); In which header file is the NULL macro defined?Answer: stdio.h and stddef.h How many bytes are occupied by near, far and huge pointers (DOS)?Answer: near=2 far=4 huge=4 If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?Answer: -> What would be the equivalent pointer expression for referring the array element a[i][j][k][l]Answer: *(*(*(*(a+i)+j)+k)+l) A pointer isAnswer: A variable that stores address of other variable The operator used to get value at address stored in a pointer variable isAnswer: * What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? #include<stdio.h> #define SWAP(a, b, c)(c t; t=a, a=b, b=t) int main() { int x=10, y=20; SWAP(x, y, int); printf("%d %d\n", x, y); return 0; }Answer: Not compile In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.hAnswer: During preprocessing The keyword used to transfer control from a function back to the calling function isAnswer: return What is the notation for following functions? 1. int f(int a, float b) { /* Some code */ } 2. int f(a, b) int a; float b; { /* Some code */ }Answer: 1. ANSI Notation 2. KR Notation What are the different types of real data type in C ?Answer: float, double, long double What will you do to treat the constant 3.14 as a long double?Answer: use 3.14L If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000 0000, what will be the output of the program (on intel machine)? #include<stdio.h> #include<math.h> int main() { float a=5.375; char *p; int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; }Answer: 00 00 AC 40 Which statement will you add in the following program to work it correctly? #include<stdio.h> int main() { printf("%f\n", log(36.0)); return 0; }Answer: #include<math.h> We want to round off x, a float, to an int value, The correct way to do isAnswer: y = (int)(x + 0.5) The binary equivalent of 5.375 isAnswer: 101.011 A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?Answer: Depends on big endian or little endian architecture What will you do to treat the constant 3.14 as a float?Answer: use 3.14f Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?Answer: rem = fmod(5.5, 1.3) Which of the following is the correct order of evaluation for the below expression? z = x + y * z / 4 % 2 - 1Answer: * / % + - = Which of the following correctly shows the hierarchy of arithmetic operations in C?Answer: / * + - Which of the following is the correct usage of conditional operators used in C?Answer: max = a>b ? a>c?a:c:b>c?b:c Which of the following is the correct order if calling functions in the below code? a = f1(23, 14) * f2(12/4) + f3();Answer: Order may vary from compiler to compiler Which of the following are unary operators in C? 1. ! 2. sizeof 3. ~ 4. &&Answer: 1, 2, 3 In which order do the following gets evaluated 1. Relational 2. Arithmetic 3. Logical 4. AssignmentAnswer: 2134 How many times the while loop will get executed if a short int is 2 byte wide? #include<stdio.h> int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0; }Answer: 255 times Which of the following is not logical operator?Answer: & In mathematics and computer programming, which is the correct order of mathematical operators ?Answer: Division, Multiplication, Addition, Subtraction