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 outpout of the following program?

#include<stdio.h>

main() 
{
      enum { india, is=7, GREAT };

      printf("%d %d", india, GREAT);
}

A - 0 1.

B - 0 2

C - 0 8

D - Compile error

Answer : C

Explanation

0 8, enums gives the sequence starting with 0. If assigned with a value the sequence continues from the assigned value.

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 - What is the output of the below code snippet.

#include<stdio.h>

main()
{
   printf("%d", -11%2);
}

A - 1

B - -1

C - 5.5

D - -5.5

Answer : B

Explanation

Modulus (%) operator is meant to give reminder for integer division.

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

#include<stdio.h>

main()
{ 
   printf("%d", !0<2);
}

A - 0

B - 1

C - False

D - True

Answer : B

Explanation

Priority of ! is greater than <. Relational operator returns 1 if relation between the expressions is true otherwise 0.

Q 6 - In Windows & Linux, how many bytes exist fornear, farandhugepointers?

A - Near: 1, far: 4, huge: 7

B - near: 4, far: 4, huge: 4

C - near: 0, far: 4, huge: 4

D - near: 4, far: 5, huge: 6

Answer : B

Explanation

In DOS, numbers of byte exist for near pointer = 2,far pointer = 4andhuge pointer = 4.

In Windows and Linux, numbers of byte exist for near pointer = 4,far pointer = 4andhuge pointer = 4.

Q 7 - For a structure, if a variable behave as a pointer then from the given below operators which operator can be used to access data of the structure via the variable pointer?

A - .

B - %

C - ->

D - #

Answer : C

Explanation

For a structure, Dot(.) operator can be used to access the data using normal structure variable and arrow (->)can be used to access the data using pointer variable.

Q 8 - Which of the following is a logical AND operator?

A - !

B - &&

C - ||

D - &

Answer : B

Explanation

Two immediate ampersand (&) symbols is logical AND operator.

Q 9 - Which files will get closed through thefclose()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 - 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 streamstdin

Advertisements