💡 C Programming MCQs and Exam Questions

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

159 solved MCQs

What will be the output of the program? #include<stdio.h> int main() { int y=128; const int x=y; printf("%d\n", x); return 0; }Answer: 128 What will be the output of the program? #include<stdio.h> #include<stdlib.h> union employee { char name[15]; int age; float salary; }; const union employee e1; int main() { strcpy(e1.name, "K"); printf("%s %d %f", e1.name, e1.age, e1.salary); return 0; }Answer: No error What will be the output of the program? #include<stdio.h> int fun(int **ptr); int main() { int i=10; const int *ptr = &i; fun(&ptr); return 0; } int fun(int **ptr) { int j = 223; int *temp = &j; printf("Before changing ptr = %5x\n", *ptr); const *ptr = temp; printf("After changing ptr = %5x\n", *ptr); return 0; }Answer: Error: cannot convert parameter 1 from 'const int **' to 'int **' What will be the output of the program? #include<stdio.h> int main() { const int x=5; const int *ptrx; ptrx = &x; *ptrx = 10; printf("%d\n", x); return 0; }Answer: Error What will be the output of the program in TurboC? #include<stdio.h> int fun(int **ptr); int main() { int i=10, j=20; const int *ptr = &i; printf(" i = %5X", ptr); printf(" ptr = %d", *ptr); ptr = &j; printf(" j = %5X", ptr); printf(" ptr = %d", *ptr); return 0; }Answer: i= FFE4 ptr=10 j=FFE2 ptr=20 What will be the output of the program? #include<stdio.h> int main() { const char *s = ""; char str[] = "Hello"; s = str; while(*s) printf("%c", *s++); return 0; }Answer: Hello What will be the output of the program? #include<stdio.h> int get(); int main() { const int x = get(); printf("%d", x); return 0; } int get() { return 20; }Answer: 20 What will be the output of the program (in Turbo C)? #include<stdio.h> int fun(int *f) { *f = 10; return 0; } int main() { const int arr[5] = {1, 2, 3, 4, 5}; printf("Before modification arr[3] = %d", arr[3]); fun(&arr[3]); printf("\nAfter modification arr[3] = %d", arr[3]); return 0; }Answer: Before modification arr[3] = 4 After modification arr[3] = 10 What will be the output of the program? #include<stdio.h> int main() { const int i=0; printf("%d\n", i++); return 0; }Answer: Error: ++needs a value What will be the output of the program? #include<stdio.h> int main() { const c = -11; const int d = 34; printf("%d, %d\n", c, d); return 0; }Answer: -11, 34 In the following code, the P2 is Integer Pointer or Integer? typedef int *ptr; ptr p1, p2;Answer: Integer pointer In the following code what is 'P'? typedef char *charp; const charp P;Answer: P is a constant What is x in the following program? #include<stdio.h> int main() { typedef char (*(*arrfptr[3])())[10]; arrfptr x; return 0; }Answer: x is an array of three function pointers In which numbering system can the binary number 1011011111000101 be easily converted to?Answer: Hexadecimal system Which bitwise operator is suitable for turning off a particular bit in a number?Answer: & operator Which bitwise operator is suitable for turning on a particular bit in a number?Answer: | operator Which bitwise operator is suitable for checking whether a particular bit is on or off?Answer: & operator The maximum combined length of the command-line arguments including the spaces between adjacent arguments isAnswer: It may vary from one operating system to another According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?Answer: int main(int argc, char *argv[]) What do the 'c' and 'v' in argv stands for?Answer: 'c' means argument count 'v' means argument vertex Which of the following function sets first n characters of a string to a given character?Answer: strnset() If the two strings are identical, then strcmp() function returnsAnswer: 0 How will you print \n on the screen?Answer: printf("\\n"); The library function used to find the last occurrence of a character in a string isAnswer: strrchr() Which of the following function is used to find the first occurrence of a given string in another string?Answer: strstr() Which of the following function is more appropriate for reading in a multi-word string?Answer: gets(); Which of the following function is correct that finds the length of a string?Answer: int xstrlen(char *s) { int length=0; while(*s!='\0') { length++; s++; } return (length); What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?Answer: The program may crash if some important data gets overwritten. What does the following declaration mean? int (*ptr)[10];Answer: ptr is a pointer to an array of 10 integers In C, if you pass an array as an argument to a function, what actually gets passed?Answer: Base address of the array