• 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() 
{
   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>

{ 
   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 - Following is the invalid inclusion of a file to the current program. Identify it.

A - #include <file>

B - #include “file”

C - #include < file

D - All of the above are invalid.

Answer : C

Explanation

option (a) & (b) are valid. There is no such syntax or provision as in option (c).

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

#include<stdio.h>

main()
{	
   int a[] = {10, 20, 30};
   
   printf("%d", *a+1);
}

A - 10

B - 20

C - 11

D - 21

Answer : C

Explanation

*a refers to 10 and adding a 1 to it gives 11.

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

#include<stdio.h>

main()
{ 
   char s1[50], s2[50] = "Hello";
   
   s1 = s2;
   printf("%s", s1);
}

A - Hello

B - No output

C - Compile error

D - Runtime error

Answer : C

Explanation

‘s1’ refers to base address and is constant. Hence raising to ‘lvalue’ required compile time error.

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 - A bitwise operator “&” can turn-off a particular bit into a number.

A - Yes

B - &&

C - *

D - ||

Answer : A

Explanation

The bitwise AND operator “&” compares each bit of the first operand with the corresponding bit of the second operand. During comparison, if both operands bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Q 8 - Which of the following statement can be used to free the allocated memory?

A - remove(var-name);

B - free(var-name);

C - vanish(var-name);

D - erase(var-name);

Answer : B

Explanation

The library function free() deallocates the memory allocated by calloc(), malloc(), or realloc().

Q 9 - Which files will get closed through the fclose() in the following program?

#include<stdio.h>

int main ()
{
   FILE *fs, *ft, *fp;
   
   fp = fopen("ABC", "r");
   fs = fopen("ACD", "r");
   ft = fopen("ADF", "r");
   fclose(fp, fs, ft);
return 0;
}

A - "ABC"

B - "ACD"

C - "ADF"

D - Return error

Answer : D

Explanation

The syntax of fclose() function is wrong; it should be int fclose(FILE *stream); closes the stream. Here, fclose(fp, fs, ft); is using separator(,) which returns error by saying that extra parameter in call to fclose() function.

#include<stdio.h>

int main ()
{
   FILE *fs, *ft, *fp;
   
   fp = fopen("ABC", "r");
   fs = fopen("ACD", "r");
   ft = fopen("ADF", "r");
   fclose(fp, fs, ft);
return 0;
}

Q 10 - In the given below statement, what does the “pf” indicate?

   int (*pf)();

A - pf is a pointer of a function which return int

B - pf is a pointer

C - pf is a function pointer

D - None of the above

Answer : A

Explanation

pf is a pointer as well holds some functions reference.

Advertisements