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() 
{
   short unsigned int i = 0; 
   
   printf("%u\n", i--);
}

A - 0

B - Compile error

C - 65535

D - 32767

Answer : A

Explanation

0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented.

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 - 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 - Choose the invalid predefined macro as per ANSI C.

A - __FILE__

B - __DATE__

C - __TIME__

D - __C++__

Answer : D

Explanation

There is no macro define with the name __C++__, but __cplusplus is defined by ANSI)

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 - How to round-off a value “5.77” to 6.0?

A - ceil(5.77)

B - round-off(5.77)

C - round-up(5.77)

D - floor(5.77)

Answer : A

Explanation

ceil( ) function in C returns nearest integer value which is greater than or equal to the argument passed to thefunction.

#include <math.h>
#include <stdio.h>

 int main()
{
   float x=5.77;
   printf("ceil of  %f is  %f\n", x, ceil(x));
   return 0;
}

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 library function can convert an unsigned long to a string?

A - ltoa() 

B - ultoa()

C - system() 

D - unsigned long can’t be converted to a string

Answer : B

Explanation

ultoa() - Convert an unsigned long integer into a string.

Q 9 - What will be the output of the following program?

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

A - 10

B - 20

C - 0

D - The program will return error

Answer : D

Explanation

The above program will return error

#include<stdio.h>

int main()
{
   const int x = 5;
   
   const int *ptrx;
   ptrx = &x;
   *ptrx = 10;
   printf("%d\n", x);
   return 0;
}

Q 10 - extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.

A - True

B - False

Answer : A

Explanation

Extern is used to resolve the scope of global identifier.


cprogramming_questions_answers.htm

Advertisements