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 your comment on the below C statement?

   signed int *p=(int*)malloc(sizeof(unsigned int));

A - Improper type casting

B - Would throw Runtime error

C - Memory will be allocated but cannot hold an int value in the memory

D - No issue with statement

Answer : D

Explanation

Option (d), as the size of int and unsigned is same, no problem in allocating memory.

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

#include<stdio.h>

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

A - 1

B - 1 2

C - No output

D - Compile error

Answer : B

Explanation

1 2, do..while is an entry control loop. As the expression x++ is post form loop continues for 2nd time also.

Answer : B

Explanation

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

Answer : C

Explanation

The text associated with the macro name gets expanded at the line of call. The expanded text is by default a double constant whereas no type is associated with PI.

Answer : B

Explanation

All the local variables are stored in a memory called as stack.

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 - Which header file can be used to define input/output function prototypes and macros?

A - math.h

B - memory.h

C - stdio.h

D - dos.h

Answer : C

Explanation

The stdio.h header is used to define variable types, macros, and various functions for performing input and output operation.

Q 8 - Which of the following statement can be used to free the allocated memory?

A - remove(var-name);

B - free(var-name);

C - vanish(var-name);

D - erase(var-name);

Answer : B

Explanation

The library function free() deallocates the memory allocated by calloc(), malloc(), or realloc().

Q 9 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A - * / % = + -

B - / * % - + =

C - - + = * % /

D - * / % + - =

Answer : D

Explanation

* / % holds highest priority than + - . All with left to right associativity.

Q 10 - The library function strrchr() finds the first occurrence of a substring in another string.

A - Yes

B - Strstr()

C - strchr()

D - strnset()

Answer : B

Explanation

Strstr() finds the first occurrence of a substring in another string.


cprogramming_questions_answers.htm

Advertisements