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() 
{
   unsigned x = 5, y=&x, *p = y+0; 

   printf("%u",*p);
}

A - Address of x

B - Address of y

C - Address of p

D - 5

Answer : D

Explanation

5, as p holds the address of x which is y+0

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

#include<stdio.h>

main()
{   
   int r, x = 2;
   float y = 5;

   r = y%x;
   printf("%d", r); 
}

A - 1

B - 0

C - 2

D - Compile error

Answer : D

Explanation

Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

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

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>

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

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : A

Explanation

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

Q 6 - The C library functionrewind()reposition the file pointer at the beginning of the file.

A - True

B - False

Answer : A

Explanation

void rewind(FILE *stream): In C, therewind functionreposition the file position to the beginning of the file of the givenstream. It also erases the error and end-of-file indicators forstream.

Q 8 - fgets() function is safer than gets() because in fgets() function you can specify the size of the buffer into which the supplied string will be stored.

A - True

D - False

Answer : A

Explanation

Both functions retrive and store a string from console or file, but fgets() functions are more safer to use then gets() because gets()doesn't facilitate to detail the length of the buffer to store the string in and fgets() facilitates to specify a maximum string length.

   char *fgets(char *s, int size, FILE *stream);
   char *gets(char *s);

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 - The library functionstrrchr() 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