• C Programming Video Tutorials

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 below code snippet?

#include<stdio.h>

main() 
{
   for()printf("Hello");
}

A - Infinite loop

B - Prints “Hello” once.

C - No output

D - Compile error

Answer : D

Explanation

Compiler error, semi colons need to appear though the expressions are optional for the ‘for’ loop.

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

#include<stdio.h>

main()
{
   int i = 1;
   
   while(i++<=5);
       printf("%d ",i++);
}

A - 4

B - 6

C - 2 6

D - 2 4

Answer : B

Explanation

6, there is an empty statement following ‘while’.

Q 3 - Choose the application option for the following program?

#include<stdio.h>

main()
{
   int *p, **q;
   
   printf("%u\n", sizeof(p));
   printf("%u\n", sizeof(q));
}

A - Both the printf() will print the same value

B - First printf() prints the value less than the second.

C - Second printf() prints the value less than the first.

D - Error in the code.

Answer : A

Explanation

Irrespective of any data type every type of pointer variable occupies same amount of memory.

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>

#define sqr(i) i*i
main()
{
   printf("%d %d", sqr(3), sqr(3+1)); 
}

A - 9 16

B - 9 7

C - Error: macro cannot be defined in lower case.

D - None of the above.

Answer : B

Explanation

The equivalent expansion is -> printf("%d %d",3*3,3+1*3+1);

Answer : A

Explanation

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

 int main()
{
   float x = 3.6;	
   
   int y = (int)(x + 0.5);
   
   printf ("Result = %d\n", y );
   return 0; 

}

Q 7 - What function can be used to free the memory allocated by calloc()?

A - dealloc();

B - strcat();

C - free();

D - memcpy();

Answer : C

Explanation

calloc(): Allocates space for an array elements, initializes to zero and then returns a pointer to memory.

Free(): Dellocate the space allocated by calloc()

Answer : B

Explanation

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

Q 9 - In the given below code, what will be return by the function get ()?

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

A - 40

B - 20

C - 0

D - Error

Answer : A

Explanation

Firstly, “int get()” which is a get() function prototype returns an integer value without any parameters.

Secondly, const int x = get(); The constant variable x is declared as an integer data type and initialized with the value of get(). Hence, the value of get() is 40, printf("%d", x); will print the value of x, that means; 40. So, the program output will be 40.

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

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.

Advertisements