💡 C Programming MCQs and Exam Questions

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

159 solved MCQs

Who was the founder of C programming language?Answer: Dennis Ritchie What will the function rewind() do?Answer: Reposition the file pointer to begining of file. Input/output function prototypes and macros are defined in which header file?Answer: stdio.h Which standard library function will you use to find the last occurance of a character in a string in C?Answer: strrchr() What is stderr ?Answer: standard error streams Does there any function exist to convert the int or float to a string?Answer: Yes What is the purpose of fflush() function.Answer: flushes all streams and specified streams. Can you use the fprintf() to display the output on the screen?Answer: Yes What will the function randomize() do in Turbo C under DOS?Answer: returns a random number generator with a random value based on time. Declare the following statement? "An array of three pointers to chars".Answer: char *ptr[3]; What do the following declaration signify? int *ptr[30];Answer: ptr is a array of 30 pointers to integers. Declare the following statement? "A pointer to an array of three chars".Answer: char (*ptr)[3]; What do the following declaration signify? char *arr[10];Answer: arr is a array of 10 character pointers. What do the following declaration signify? int (*pf)();Answer: pf is a pointer to a function which return int Declare the following statement? "A pointer to a function which receives an int pointer and returns float pointer".Answer: float *(*ptr)(int*) What do the following declaration signify? void *cmp();Answer: cmp is a function that return a void pointer. Declare the following statement? "A pointer to a function which receives nothing and returns nothing".Answer: void (*ptr)() What do the following declaration signify? int *f();Answer: f is a function returning pointer to an int. What do the following declaration signify? void (*cmp)();Answer: cmp is a pointer to a function which returns void . What do the following declaration signify? char **argv;Answer: argv is a pointer to a char pointer. What do the following declaration signify? char *scr;Answer: scr is a pointer to char. What will be the output of the program? #include<stdio.h> #include<stdarg.h> void fun(char *msg, ...); int main() { fun("IndiaBIX", 1, 4, 7, 11, 0); return 0; } void fun(char *msg, ...) { va_list ptr; int num; va_start(ptr, msg); num = va_arg(ptr, int); num = va_arg(ptr, int); printf("%d", num); }Answer: 4 What will be the output of the program? #include<stdio.h> #include<stdarg.h> void fun1(char, int, int *, float *, char *); void fun2(char ch, ...); void (*p1)(char, int, int *, float *, char *); void (*p2)(char ch, ...); int main() { char ch='A'; int i=10; float f=3.14; char *p="Hello"; p1=fun1; p2=fun2; (*p1)(ch, i, &i, &f, p); (*p2)(ch, i, &i, &f, p); return 0; } void fun1(char ch, int i, int *pi, float *pf, char *p) { printf("%c %d %d %f %s \n", ch, i, *pi, *pf, p); } void fun2(char ch, ...) { int i, *pi; float *pf; char *p; va_list list; printf("%c ", ch); va_start(list, ch); i = va_arg(list, int); printf("%d ", i); pi = va_arg(list, int*); printf("%d ", *pi); pf = va_arg(list, float*); printf("%f ", *pf); p = va_arg(list, char *); printf("%s", p); }Answer: A 10 10 3.140000 Hello A 10 10 3.140000 Hello What will be the output of the program? #include<stdio.h> #include<stdarg.h> void dumplist(int, ...); int main() { dumplist(2, 4, 8); dumplist(3, 6, 9, 7); return 0; } void dumplist(int n, ...) { va_list p; int i; va_start(p, n); while(n-->0) { i = va_arg(p, int); printf("%d", i); } va_end(p); printf("\n"); }Answer: 4 8 6 9 7 What will be the output of the program? #include<stdio.h> #include<stdarg.h> void display(int num, ...); int main() { display(4, 'A', 'B', 'C', 'D'); return 0; } void display(int num, ...) { char c, c1; int j; va_list ptr, ptr1; va_start(ptr, num); va_start(ptr1, num); for(j=1; j<=num; j++) { c = va_arg(ptr, int); printf("%c", c); c1 = va_arg(ptr1, int); printf("%d\n", c1); } }Answer: A, 65 B, 66 C, 67 D, 68 What will be the output of the program? #include<stdio.h> #include<stdarg.h> void fun1(int num, ...); void fun2(int num, ...); int main() { fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0; } void fun1(int num, ...) { char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str); } void fun2(int num, ...) { va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num); }Answer: Apple 12 Which header file should be included to use functions like malloc() and calloc()?Answer: stdlib.h What function should be used to free the memory allocated by calloc() ?Answer: free(); How will you free the memory allocated by the following program? #include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4 int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }Answer: free(p); Specify the 2 library functions to dynamically allocate memory?Answer: malloc() and calloc()