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

main() 
{ 
   int const a = 5; 
   
   a++; 
   printf(%d,a); 
} 

A - 5

B - 6

C - Runtime error

D - Compile error

Answer : D

Explanation

Compile error - constant variable cannot be modified.

main() 
{ 
   int const a = 5; 
   
   a++; 
   printf(%d,a); 
} 

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

#include

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 - What is the output of the following program?

#include

main()
{ 
   int a[3] = {2,1};
   
   printf("%d", a[a[1]]); 
}

A - 0

B - 1

C - 2

D - 3

Answer : B

Explanation

1, The inner indirection evaluates to 1, and the value at index 1 for outer indirection is 1.

Answer : A

Explanation

When the program is in execution phase the possible unavoidable error is called as an exception.

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

#include

main()
{
   char *s = "Fine";
   *s = 'N';
   
   printf("%s", s);
}

A - Fine

B - Nine

C - Compile error

D - Runtime error

Answer : D

Explanation

*s=N, trying to change the character at base address to N of a constant string leads to runtime 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 tothe argument passed to thefunction.

#include 
#include 

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

Q 7 - The equivalent pointer expression by using the array elementa[i][j][k][2],

A - ((((a+m)+n)+o)+p)

B - *(*(*(*(a+i)+j)+k)+2)

C - *( (((a+m)+n)+o+p)

D - *( ((a+m)+n+o+p)

Answer : B

Explanation

If, the array elementis a[i][j] = *(*(a+i)+j)

If, the array elementis a[i][j][k]= *(*(*(a+i)+j)+k)

Q 8 - Choose the correct statement that is a combination of these two statements,

   Statement 1: char *p;
   
   Statement 2: p = (char*) malloc(100);

A - char p = *malloc(100);

B - char *p = (char*)malloc(100);

C - char *p = (char) malloc(100);

D - None of the above

Answer : B

Explanation

ptr = (data type *)malloc(size);

The given above code is a prototype of malloc() function, where ptr indicates the pointer.

char *p = (char*)malloc(100);

In this code, *p is a pointer of type char and malloc() function allocates the memory for char.

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