C Programming Online Quiz


Advertisements


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

Q 1 - What is the output of the following code snippet?

#include<stdio.h>

main() 
{
   int x = 5;
   
   if(x=5)
   {	
       if(x=5) break;
       printf("Hello");
   } 
   printf("Hi");
}

A - Compile error

B - Hi

C - HelloHi

D - Compiler warning

Answer : A

Explanation

compile error, keyword break can appear only within loop/switch statement.

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

#include<stdio.h>

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

A - 1

B - 2

C - Compile error

D - Runtime error

Answer : B

Explanation

2, as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

Q 3 - Function fopen() with the mode "r+" tries to open the file for __

A - reading and writing

B - reading and adding new content

C - only for reading

D - it works only for directories

Answer : A

Explanation

Option (a), the file should exist and opens for both reading & writing.

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

#include<stdio.h>

int x = 5;
int* f() 
{
   return &x;
}
main()
{	
   *f() = 10;
   
   printf("%d", x);
}

A - Compile error

B - Runtime error

C - 5

D - 10

Answer : D

Explanation

The returned address is global variables and 10 being stored in it. Therefore x is 10.

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

#include<stdio.h>

main()
{ 
   int x = 3;
   
   x += 2;
   x =+ 2;
   printf("%d", x); 
}

A - 2

B - 5

C - 7

D - Compile error

Answer : A

Explanation

+ in unary form is dummy operator, therefore ‘x’ is overwritten with the value +2 finally.

Q 6 - Where to place “f” with a double constant 3.14 to specify it as a float?

A - (float)(3.14)(f)

B - (f)(3.14)

C - 3.14f

D - f(3.14)

Answer : C

Explanation

A floating-point constant without an f, F, l, or L suffix has type double. If the letter f or F is the suffix, the constant has type float. If suffixed by the letter l or L, it has type long double.

Answer : B

Explanation

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

Answer : B

Explanation

Explanation: with or without the brackets surrounding the *p, still the declaration says it’s an array of pointer to integers.

Answer : B

Explanation

As per the operators preference.

Q 10 - What will be the output of the given below code?

#include<stdio.h>

int main()
{
   const int *ptr = &i;
   
   char str[] = "Welcome";
   s = str;
   while(*s)
   printf("%c", *s++);
   return 0;
}

A - Welcome

B - 0

C - Wel

D - Come

Answer : A

Explanation

Although, char str[] = "Welcome"; and s = str;, the program will print the value of s.

#include<stdio.h>

int main()
{
   const int *ptr = &i;
   
   char str[] = "Welcome";
   s = str;
   while(*s)
   printf("%c", *s++);
   return 0;
}


cprogramming_questions_answers.htm

Advertisements