C programming language multiple type questions for exams point of view
Basic C programming MCQ |
1) What is the 16-bit compiler allowable range for integer constants?
Explanation: In a 16-bit C compiler, we have 2 bytes to store the value.
2) Study the following program: main() {printf("mskuthar"); main();} What will be the output of this program?
Answer: (b) It will keep on printing mskuthar. Explanation: In this program, the main function will call itself again and again. Therefore, it will continue to print mskuthar. 3) What is required in each C program?
Explanation: Every C program contains at least one function, and even the simplest programs can have additional functions specified. A function is a code snippet. In other words, it functions similarly to a sub-program. 4) What will this program print? main() { int i = 2; { int i = 4, j = 5; printf("%d %d", i, j); } printf("%d %d", i, j); }
Explanation: The inner value of the function will be printed first, followed by the outer value of the function, in this program. 5) Which of the following comment is correct when a macro definition includes arguments?
Answer: (a) The opening parenthesis should immediately follow the macro name. 6) What is a lint?
Explanation: Lint is a code analysis tool that looks for suspicious constructs, stylistic flaws, bugs, and programming faults in source code. Lint is a compiler-like application that parses C programming source files. It verifies the files' syntactic accuracy. 7) What is the output of this statement "printf("%d", (a++))"?
Answer: (b) The current value of "a". 8) Study the following program: main() { char x [10], *ptr = x; scanf ("%s", x); change(&x[4]); } change(char a[]) { puts(a); } If abcdefg is the input, the output will be
9) Study the following program:
What will be the output of this program?
Explanation: It is an effect of the comma operator. a + = (a + = 3, 5, a) It first evaluates to "a + = 3" i.e. a = a + 3 then evaluate 5 and then evaluate "a". Therefore, we will get the output is 4. Then, a + = 4 It gives 8 as the output. 10) What does this declaration mean? int x : 4;
Explanation: This means, "X" is a four-bit integer. 11) Why is a macro used in place of a function?
Explanation: Macro is used in place of a function because it reduces code size, and very efficient. 12) In the C language, the constant is defined _______.
Explanation: In the C language, the constant is defined anywhere, but starting on a new line. 13) How many times will the following loop execute? for(j = 1; j <= 10; j = j-1)
14) A pointer is a memory address. Suppose the pointer variable has p address 1000, and that p is declared to have type int*, and an int is 4 bytes long. What address is represented by expression p + 2?
15) What is the result after execution of the following code if a is 10, b is 5, and c is 10? If ((a > b) && (a <= c)) a = a + 1; else c = c+1;
16) Which one of the following is a loop construct that will always be executed once?
Explanation: During the do-while loop, the body of a loop is frequently run at least once. The condition is tested after the body has been conducted. If the condition is true, the loop's body will be executed; otherwise, control will be moved out of the loop. 17) Which of the following best describes the ordering of destructor calls for stack-resident objects in a routine?
18) How many characters can a string hold when declared as follows? char name[20]:
19) Directives are translated by the
Explanation: The pre-processor is a macro processor in the C programming language that allows the programmer to alter the program before it is properly built (Before construction, pro-processor directives are implemented). 20) How many bytes does "int = D" use?
Explanation: The int type takes 2 or 4 bytes. 21) What feature makes C++ so powerful?
22) Which of the following will copy the null-terminated string that is in array src into array dest?
Explanation: strcpy is a string function that is used to copy the string between the two files. strcpy(destination, source) 23) In the statement "COUT << "mskuthar" << end1;", end1 is a ___.
Explanation: End1 is an I/O manipulator that takes effect in printing a new line '\ n' character and then flushing the output stream. 24) Each instance of a class has a different set of
Explanation: Each instance of the class has a different set of attribute values |