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

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

#include<stdio.h>

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

Answer : A

Explanation

a=5,b=3 , as there are only two format specifiers for printing.

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

#include<stdio.h>

main()
{ 
   int a[] = {1,2}, *p = a;
   
   printf("%d", p[1]); 
}

A - 1

B - 2

C - Compile error

D - Runtime error

Answer : B

Explanation

2, as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

Q 3 - A macro can execute faster than a function.

A - true

B - false

Answer : A

Explanation

As the code of macro gets expanded at the line of call, therefore macro gets executed faster with no overhead of context switch.

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

#include<stdio.h>

main()
{	
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!

B - No output

C - Compile error

D - Runtime error

Answer : C

Explanation

stdout is the identifier declared in the header file stdio.h, need to include the same.

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

#include<stdio.h>

int main();
void main()
{
   printf("Okay"); 
}

A - Okay

B - No output

C - Compile error. We cannot declare main() function.

D - Compile error. Mismatch in declaration & definition.

Answer : D

Explanation

It’s compile error as the declaration of main() mismatches with the definition.

Q 6 - In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?

A - math.h

B - conio.h

C - dos.h

D - stdio.h

Answer : A

Explanation

math.h is a header file in the standard library designed for basic mathematical operations

Q 7 - Which of the following is a logical OR operator?

A - &

B - &&

C - ||

D - None of the above

Answer : C

Explanation

&& = Called Logical AND operator. If both the operands are non-zero, then condition becomes true.

|| = Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.

! = Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then

Logical NOT operator will make false.

Answer : A

Explanation

In C programming, the fflush() function writes any unwritten data in stream's buffer. If, stream is a null pointer, fflush() function will flush all streams with unwritten data in the buffer.

int fflush(FILE *stream);

Q 9 - To print a double value which format specifier can be used?

A - %L

B - %lf

C - %Lf

D - None of the above

Answer : B

Explanation

Double value can be printed using %lf format specifier.

Q 10 - Choose the function that is most appropriate for reading in a multi-word string?

A - strnset()

B - scanf()

C - strchr()

D - gets()

Answer : D

Explanation

gets (); = Collects a string of characters terminated by a new line from the standard input stream stdin

Advertisements