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()
{ 
   int *p = 15; 
   printf("%d",*p);
}

A - 15

B - Garbage value

C - Runtime error

D - Compiler error

Answer : C

Explanation

Runtime error, as the pointer variable is not holding proper address, writing/reading the data from the same raises runtime error.

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.

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

#include<stdio.h>

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.

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

#include<stdio.h>

main() 
{
   char *p = NULL;
   
   printf("%c", *p);
}

A - NULL

B - 0

C - Compile error

D - Runtime error.

Answer : D

Explanation

It is invalid to access the NULL address hence giving run time error.

Q 5 - C is the successor of ___ programming language.

A - C++

B - B++

C - B

D - Mini C

Answer : C

Explanation

Bis a programming language developed atBell Labsin 1969. It is derived from BCPL (Basic Combined Programming Language). It is designed byKen ThompsonwithDennis Ritchie.

Q 6 - Where to place f with a double constant 3.14 to specify it as afloat?

A - (float)(3.14)(f)

B - (f)(3.14)

C - 3.14f

D - f(3.14)

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 - For a structure, if a variable behave as a pointer then from the given below operators which operator can be used to access data of the structure via the variable pointer?

A - .

B - %

C - ->

D - #

Answer : C

Explanation

For a structure, Dot(.) operator can be used to access the data using normal structure variable and arrow (->)can be used to access the data using pointer variable.

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 - Which of the following statement shows the correct implementation of nested conditional operation by finding greatest number out of three numbers?

A - max = a>b ? a>c?a:c:b>c?b:c

B - a=b ? c=30;

C - a>b : c=30 : c=40;

D - return (a>b)?(a:b) ?a:c:b

Answer : A

Explanation

Syntax is exp1?exp2:exp3. Any exp can be a valid expression.

Q 10 - In the given below code, what will be the value of a variable x?

#include<stdio.h>

int main()
{
    int y = 100;
    const int x = y;
    
    printf("%d\n", x);
    return 0;
}

A - 100

B - 0

C - Print x

D - Return Error

Answer : A

Explanation

Although, integer y = 100; and constant integer x is equal to y. here in the given above program we have to print the x value, so that it will be 100.

Advertisements