• C Programming Video Tutorials

C Programming - Online Quiz



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
cprogramming_questions_answers.htm

Q 1 - What is the output of the below code snippet?

#include<stdio.h>

main() 
{ 
   char s[]="hello", t[]="hello";
   
   if(s==t){
	   printf("eqaul strings");
	}
}

A - Equal strings

B - Unequal strings

C - No output

D - Compilation error

Answer : C

Explanation

No output, as we are comparing both base addresses and they are not same.

Q 2 - What is the output of the following program?

#include<stdio.h>

main()
{
   int i = 1;
   
   while( i++<=5 )
      printf("%d ",i++);
}

A - 1 3 5

B - 2 4

C - 2 4 6

D - 2

Answer : C

Explanation

2 4 6, at while first compared and later incremented and in printf printed first and incremented later.

Q 3 - Identify the invalid constant used in fseek() function as ‘whence’ reference.

A - SEEK_SET

B - SEEK_CUR

C - SEEK_BEG

D - SEEK_END

Answer : C

Explanation

SEEK_BEG, all the rest are valid constants defined in ‘stdio.h’

Answer : C

Explanation

The text associated with the macro name gets expanded at the line of call. The expanded text is by default a double constant whereas no type is associated with PI.

Q 5 - Which of the following functions disconnects the stream from the file pointer.

A - fremove()

B - fclose()

C - remove()

D - file pointer to be set to NULL

Answer : B

Explanation

fclose(), it flushes the buffers associated with the stream and disconnects the stream with the file.

Answer : A

Explanation

In C programming, NULL indicates the value 0 of a pointer, which means; pointer that initializes with NULL value considered as NULL pointer.

Q 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

Answer : C

Explanation

The stdio.h header is used to define variable types, macros, and various functions for performing input and output operation.

Q 8 - Which of the following is a logical AND operator?

A - !

B - &&

C - ||

D - &

Answer : B

Explanation

Two immediate ampersand (&) symbols is logical AND operator.

Q 9 - Choose the correct unary operators in C – a) !, b) ~, c) ^&, d) ++

A - a, b, d

B - a, b, c

C - b, c, d

D - c, d, a

Answer : A

Explanation

In C, these are the unary operators,

   Logical NOT = !
   Address-of = &
   Cast Operator = ( )
   Pointer dereference = *
   Unary Plus = +
   Increment = ++
   Unary negation = –

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.

Advertisements