• 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 - Which operator is used to continue the definition of macro in the next line?

A - #

B - ##

C - $

D - \

Answer : D

Explanation

\, the first two are stringize and token pasting operators respectively. There is no such operator called $.

Q 3 - Identify the C compiler of UNIX.

A - gcc

B - cc

C - Borland

D - vc++

Answer : B

Explanation

‘cc’ full form is C Compiler and is the compiler for UNIX. gcc is GNU C compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

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

#include<stdio.h>

main()
{	
   fprintf(stdout,"Hello, World!");
}

A - Hello, World!

B - No output

C - Compile error

D - Runtime error

Answer : C

Explanation

stdout is the identifier declared in the header file stdio.h, need to include the same.

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

#include<stdio.h>

main()
{ 
   int x;
   float y;
   
   y = x = 7.5;
   printf("x=%d y=%f", x, y);
}

A - 7 7.000000

B - 7 7.500000

C - 5 7.500000

D - 5 5.000000

Answer : A

Explanation

‘x’ gets the integral value from 7.5 which is 7 and the same is initialized to ‘y’.

Answer : B

Explanation

In the C Programming Language, the fmod() function compute and returns the floating-point remainder when x is divided by y.

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

int main( void )
{
   double x = -10.0, y = 3.0, z;

   z = fmod( x, y );
   printf( "The remainder of %.2f / %.2f is %f\n", w, x, z );
}

Q 7 - Which library function can convert an integer/long to a string?

A - ltoa()

B - ultoa()

C - sprintf()

D - None of the above

Answer : A

Explanation

In C, ltoa() function converts long/integer data type to string data type.

char *ltoa(long N, char *str, int base);

Q 8 - Which of the following is a logical AND operator?

A - !

B - &&

C - ||

D - &

Answer : B

Explanation

Two immediate ampersand (&) symbols is logical AND operator.

Q 9 - Choose the correct order from given below options for the calling function of the code “a = f1(23, 14) * f2(12/4) + f3();”?

A - f1, f2, f3

B - f3, f2, f1

C - f2, f1, f3

D - Order may vary from one compiler to another

Answer : D

Explanation

Evaluation order is implementation dependent.

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