C Programming Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - int x=~1; What is the value of 'x'?

A - 1

B - -1

C - 2

D - -2

Answer : D

Explanation

-2, the one’s compliment of 1 is 1110 (binary) which is equivalent to two’s compliment of 2, ie -2.

Q 2 - What is the following program doing?

#include<stdio.h>

main()
{
   FILE *stream=fopen("a.txt",'r');
}

A - Trying to open “a.txt” in read mode

B - Trying to open “a.txt” in write mode.

C - “stream” is an invalid identifier

D - Compile error

Answer : D

Explanation

Compile error, second argument for fopen is invalid, should be a string.

Q 3 - Following is the invalid inclusion of a file to the current program. Identify it.

A - #include <file>

B - #include “file”

C - #include < file

D - All of the above are invalid.

Answer : C

Explanation

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

Answer : A

Explanation

When the program is in execution phase the possible unavoidable error is called as an exception.

Q 5 - What is the output of the following statement?

#include<stdio.h>

main()
{ 
   printf("%d", !0<2);
}

A - 0

B - 1

C - False

D - True

Answer : B

Explanation

Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.

Q 6 - Choose the correct statement that can retrieve the remainder of the division 5.5 by 1.3?

A - rem = modf(5.5 % 1.3)

B - rem = modf(5.5, 1.3)

C - rem = fmod(5.5, 1.3)

D - rem = f(5.5, 1.3)

Answer : C

Explanation

A floating-point constant without an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long double.

Q 7 - Which library function can convert an integer/long to a string?

A - ltoa()

B - ultoa()

C - sprintf()

D - None of the above

Answer : A

Explanation

In C, ltoa() function converts long/integer data type to string data type.

char *ltoa(long N, char *str, int base);

Answer : B

Explanation

Explanation: with or without the brackets surrounding the *p, still the declaration says it’s an array of pointer to integers.

Q 9 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A - * / % = + -

B - / * % - + =

C - - + = * % /

D - * / % + - =

Answer : D

Explanation

* / % holds highest priority than + - . All with left to right associativity.

Q 10 - Which statement can print \n on the screen?

A - printf("\\n");

B - printf("n\");

C - printf("n");

D - printf('\n');

Answer : A

Explanation

Option A is the correct answer. In C programming language, "\n" is the escape sequence for printing a new line character. In printf("\\n"); statement, "\\" symbol will be printed as "\" and “n” will be known as a common symbol.


cprogramming_questions_answers.htm

Advertisements