• 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 following code snippet?

#include<stdio.h>

main() 
{
   short unsigned int i = 0; 
   
   printf("%u\n", i--);
}

A - 0

B - Compile error

C - 65535

D - 32767

Answer : A

Explanation

0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented.

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 - What is the output of the following program?

#include<stdio.h>

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

A - 0

B - 1

C - 2

D - Compile error.

Answer : C

Explanation

2, as ‘a’ refers to base address.

Q 4 - Choose the correct option in respect to the following program.

#include<stdio.h>

void f(int const i) 
{
   i=5;
}
main() 
{
   int x = 10;
   
   f(x);
}
  • I - Error in the statement ‘void f(int const i)’

  • II - Error in the statement i=5.

A - Statements I & II are true

B - Statements I & II are false.

C - Statement I is true

D - Statement II is true.

Answer : D

Explanation

We cannot modify a constant as in statement i=5.

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

#include<stdio.h>

main()
{ 
   char s[20] = "Hello\0Hi";
   
   printf("%d %d", strlen(s), sizeof(s));
}

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : C

Explanation

Length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.

Q 6 - In C, what are the various types of real data type (floating point data type)?

A - Float, long double

B - long double, short int

C - float, double, long double

D - short int, double, long int, float

Answer : C

Explanation

There are three types of floating point data type = 1) float with storage size 4 byte, 2) double with storage size 8 byte, and 3) long double with storage size 10 byte.

Answer : B

Explanation

Standard error stream (Stderr) = Any program use it for error messages and diagnostics issue.

Q 8 - The return keyword used to transfer control from a function back to the calling function.

A - Yes

B - Switch

C - go back

D - goto

Answer : A

Explanation

In C, the return function stops the execution of a function and returns control with value to the calling function. Execution begins in the calling function by instantly following the call.

Q 9 - In C, what is the correct hierarchy of arithmetic operations?

A - */ + -

B - * +- /

C - / *+ -

D - + - / *

Answer : C

Explanation

In C, there are 5 arithmetic operators (+, -, *, /, and %) that can be used in performing arithmetic operations.

Q 10 - In the given below code, what will be the value of a variable x?

#include<stdio.h>

int main()
{
    int y = 100;
    const int x = y;
    
    printf("%d\n", x);
    return 0;
}

A - 100

B - 0

C - Print x

D - Return Error

Answer : A

Explanation

Although, integer y = 100; and constant integer x is equal to y. here in the given above program we have to print the x value, so that it will be 100.

Advertisements