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 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.

Answer : B

Explanation

(b). Compilation is the process of translating high level language statements into equivalent machine code, which is object code.

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

#include<stdio.h>

void f() 
{
   static int i = 3;
   
   printf("%d ", i);
   if(--i) f();
}
main() 
{
   f();
}

A - 3 2 1 0

B - 3 2 1

C - 3 3 3

D - Compile error

Answer : B

Explanation

As the static variable retains its value from the function calls, the recursion happens thrice.

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

#include<stdio.h>

main()
{ 
   char s[20] = "Hello\0Hi";
   
   printf("%d %d", strlen(s), sizeof(s));
}

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : C

Explanation

Length of the string is count of character upto \0. sizeof reports the size of the array.

Q 6 - Choose the correct statement that can retrieve the remainder of the division 5.5 by 1.3?

A - rem = modf(5.5 % 1.3)

B - rem = modf(5.5, 1.3)

C - rem = fmod(5.5, 1.3)

D - rem = f(5.5, 1.3)

Answer : C

Explanation

A floating-point constant without anf,F,l, orLsuffix has typedouble. If the letterforFis the suffix, the constant has typefloat. If suffixed by the letterlorL, it has typelong double.

Q 7 - In Decimal system you can convert the binary number1011011111000101very easily.

A - Yes

B - Hexadecimal system

C - Octal system

D - Both, Octal & Decimal

Answer : B

Explanation

Hexadecimal is also known ashexorbase 16. It is a system help in writing and presenting numerical values. Binary(base 2) is a popular numeral system (represent numbers by just two digit values 0 and 1), used to present the language of computers. Hexadecimal system can easily convert those numbers.

Q 8 - Which library function can convert an unsigned long to astring?

A - ltoa()

B - ultoa()

C - system()

D - unsigned long cant be converted to astring

Answer : B

Explanation

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

Q 9 - What will be the resultant of the given below program?

#include<stdio.h>
#include<stdarg.h>

Void fun(char *msg, ...);
int main ()
{
   fun("IndiaMAX", 1, 4, 7, 11, 0);
   return 0;
}
   void fun(char *msg, ...)  
{
va_list ptr;{
   int num;
   va_start(ptr, msg);
   num = va_arg(ptr, int);    
   num = va_arg(ptr, int);
   printf("%d", num);
}

A - IndiaMAX 1, 7, 11, 0

B - IndiaMAX 1, 7

C - Only 4

D - 1, 7, 11, 0

Answer : C

Explanation

va_list ptr is an argument pointer that traverse through the variable arguments passed in the function, where, va_start points 'ptr' to the first argument (IndiaMix). In each call to the va_arg, ptr shift to the next variable argument and after two calls ptr ends up at '7' and return the number '4'.

#include<stdio.h>
#include<stdarg.h>

Void fun(char *msg, ...);
int main ()
{
   fun("IndiaMAX", 1, 4, 7, 11, 0);
   return 0;
}
   void fun(char *msg, ...)  
{
va_list ptr;{
   int num;
   va_start(ptr, msg);
   num = va_arg(ptr, int);    
   num = va_arg(ptr, int);
   printf("%d", num);
}

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