Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and choose over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer link.
1. What is the output of the below code snippet?
#include main() { int a = 5, b = 3, c = 4; printf("a = %d, b = %d\n", a, b, c); }
A – a=5, b=3
B – a=5, b=3, c=0
C – a=5, b=3, 0
D – compile error
Explaination: a=5,b=3 , as there are only two format specifiers for printing.
2. What is the output of the following program?
#include main() { struct { int x;} var = {5}, *p = &var; printf("%d %d %d",var.x,p->x,(*p).x); }
A – 5 5 5
B – 5 5 garbage value
C – 5 5 0
D – Compile error
Explaination: 5 5 5, the two possible ways of accessing structure elements using pointer is by using -> (arrow operator) OR *.
3. Identify the incorrect file opening mode from the following
A – r
B – w
C – x
D – a
Explaination: x, there is no such mode called “x”.
4. What is the output of the below code snippet.
#include main() { printf("%d", -11%2); }
A – 1
B – -1
C – 5.5
D – -5.5
Explaination: Modulus (%) operator is meant to give reminder for integer division.
5. What is the built in library function to compare two strings?
A – string_cmp()
B – strcmp()
C – equals()
D – str_compare()
Explaination: strcmp() is the built in function from “string.h” to compare two strings. Returns 0 if both are same strings. Returns -1 if first < second string. Returns 1 first > second.
6. In C programming language, a function prototype is a declaration of the function that just specifies the function’s interface (function’s name, argument types and return type) and extracts the body of the function. By defining the function, we get to know what action a particular function is going to perform.
A – True
B – False
Explaination: The function body shall associate a specific task, hence representing the action.
7. Which header file can be used to define input/output function prototypes and macros?
A – math.h
B – memory.h
C – stdio.h
D – dos.h
Explaination: The stdio.h header is used to define variable types, macros, and various functions for performing input and output operation.
8. Which library function can convert an unsigned long to a string?
A – ltoa()
B – ultoa()
C – system()
D – unsigned long can’t be converted to a string
Explaination: ultoa() – Convert an unsigned long integer into a string.
9. What value strcmp() function returns when two strings are the same?
A – 0
B – 2
C – 1
D – Error
Explaination: The C library function strcmp() compares two strings with each other and return the value accordingly.
int strcmp(const char *str1, const char *str2)
Comparison happens between first string (str1) with second string (str2).
By comparing two strings, the values return by the function strcmp() are,
- If, str1 is less than str2 then Return value < 0
- If, str2 is less than str1 then Return value > 0
- If, str1 is equal to str2 then Return value = 0
10. In the given below statement, what does the “arr” indicate?
char *arr[30];
A – arr is a array of function
B – arr is a array of 30 characters
C – arr is a pointer to an array
D – arr is a array of 30 character pointers
Explaination: square parenthesis signify as array at declaration and type is char*, so array of character pointers.