• 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() 
{
    char c = 'A'+255;
   
    printf("%c", c);
}

A - A

B - B

C - Overflow error at runtime

D - Compile error

Answer : A

Explanation

A, the range of ASCII values for the ASCII characters is 0-255. Hence the addition operation circulates back to ‘A’

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

#include<stdio.h>

{ 
   int x = 1;
   switch(x) 
   {
      default: printf("Hello");
      case 1: printf("hi"); break;
   }
}

A - Hello

B - Hi

C - HelloHi

D - Compile error

Answer : B

Explanation

Hi, control reaches default-case after comparing the rest of case constants.

Q 3 - Choose the invalid identifier from the below

A - Int

B - volatile

C - DOUBLE

D - __0__

Answer : B

Explanation

volatile is the reserved keyword and cannot be used an identifier name.

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

#include<stdio.h>

main() 
{
   char *p = NULL;
   
   printf("%c", *p);
}

A - NULL

B - 0

C - Compile error

D - Runtime error.

Answer : D

Explanation

It is invalid to access the NULL address hence giving run time error.

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

#include<stdio.h>

main()
{
   printf("%d", -1<<1 );  
}

A - 2

B - -2

C - 1

D - -1

Answer : B

Explanation

A negative number stored in two’s compliment of positive number. After shifting we get 1110, which is equivalent to -2.

Q 6 - A Variable name in C includes which special symbols?

A - * (asterisk)

B - # (Hash)

C - + (Addition)

D - _ (underscore)

Answer : D

Explanation

Characters which are allowed and not allowed with variable name,

  • Underscore(_) allowed
  • Capital Letters ( A – Z ) allowed
  • Small Letters ( a – z ) allowed
  • Digits ( 0 – 9 ) allowed
  • First Character should be alphabet or Underscore
  • Blanks & Commas not allowed
  • Special Symbols not allowed, but Underscore(_)allowed
  • Reserved Word not allowed

Answer : B

Explanation

It is BODMAS.

Q 8 - Which scanf() statement will you use to scan a float value (a) and double value (b)?

   Float a;
   
   Double b;

A - scanf("%f %f", &a, &b);

B - scanf("%lf % lf ", &a, &b);

C - scanf("%Lf %Lf", &a, &b);

D - scanf("%f %lf", &a, &b);

Answer : D

Explanation

In C Programming, the scanf() can be used to read a formatted string from the stdin stream, where as; scanf() uses %lf to read a double value and %f to read a floating-point number in fixed decimal format.

int scanf(const char *format, ...)

Answer : A

Explanation

Preprocessing enlarges and boosts the C programming language by replacing preprocessing directive “#include<stdio.h>” with the content of the file stdio.h.

Q 10 - The library function strrchr() finds the first occurrence of a substring in another string.

A - Yes

B - Strstr()

C - strchr()

D - strnset()

Answer : B

Explanation

Strstr() finds the first occurrence of a substring in another string.

Advertisements