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 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 size of ‘int’?

A - 2

B - 4

C - 8

D - Compiler dependent

Answer : D

Explanation

The size of ‘int’ depends upon the complier i.e. whether it is a 16 bit or 32 bit.

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

#include<stdio.h>

main()
{ 
   int i = 13, j = 60;
   
   i ^= j;
   j ^= i;
   i ^= j;
   
   printf("%d %d", i, j);
}

A - 73 73

B - 60 13

C - 13 60

D - 60 60

Answer : B

Explanation

60 13, its swapping.

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 - C is the successor of ___ programming language.

A - C++

B - B++

C - B

D - Mini C

Answer : C

Explanation

B is a programming language developed at Bell Labs in 1969. It is derived from BCPL (Basic Combined Programming Language). It is designed by Ken Thompson with Dennis Ritchie.

Q 6 - Turbo C in 16 bit DOS OS, the correct range of “long double” is,

A - 3.4E-4932 to 3.4E+4932

B - 3.4E-4932 to 1.1E+4932

C - 4.1E-4932 to 5.1E+4932

D - 0.7E-4932 to 1.8E+4932

Answer : B

Explanation

Explanation: The integral and precession value varies depending upon the number of bytes designated for a particular data type.

Answer : B

Explanation

A structure, union and enumeration all of them can define a new data type.

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 i = 0;
    
   printf("%d\n", i++);
   return 0;
}

A - 100

B - Infinity

C - 0

D - Return error

Answer : D

Explanation

It is because ++needs a value and a const variable can’t be modified.

#include<stdio.h>

int main()
{
   const int i = 0;
    
   printf("%d\n", i++);
   return 0;
}

Q 10 - According to ANSI specification, how to declare main () function with command-line arguments?

A - int main(int argc, char *argv[])

B - int char main(int argc, *argv)

C -

int main()
{
   Int char (*argv argc);
)

D - None of the above

Answer : A

Explanation

Some time, it becomes necessary to deliver command line values to the C programming to execute the particular code when the code of the program is controlled from outside. Those command line values are called command line arguments. The command line arguments are handled by the main() function.

Declaration of main () with command-line argument is,

int main(int argc, char *argv[])

Where, argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program.

Advertisements