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
cprogramming_questions_answers.htm

Q 1 - What is the output of the below code snippet?

#include<stdio.h>

main() 
{ 
   int a = 1; 
   float b = 1.3; 
   double c;
   
   c = a + b; 
   printf("%.2lf", c);
}

A - 2.30

B - 2.3

C - Compile error

D - 2.0

Answer : A

Explanation

2.30, addition is valid and after decimal with is specified for 2 places.

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 - 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 - Which of the following is used in mode string to open the file in binary mode?

A - a

B - b

C - B

D - bin

Answer : B

Explanation

To perform unformatted data I/O a file is opened in binary mode and is represented with the alphabet ‘b’ in the mode string.

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

#include<stdio.h>

main()
{ 
   char s[20] = "Hello\0Hi";
   
   printf("%d %d", strlen(s), sizeof(s));
}

A - 5 9

B - 7 20

C - 5 20

D - 8 20

Answer : C

Explanation

Length of the string is count of character upto ‘\0’. sizeof – reports the size of the array.

Q 6 - The binary equivalent of 50 is,

A - 110010

B - 1010110

C - 101

D - 101.011.00.00

Answer : A

Explanation

#include <stdio.h>

 int main()
{
   long int decimalNumber,remainder,quotient;
    int binaryNumber[100], i = 1, j;

    printf("Enter any decimal number: ");
    scanf("%ld",&decimalNumber);
    quotient = decimalNumber;
    while(quotient!=0){
           binaryNumber[i++]= quotient % 2;
    quotient = quotient / 2;
    }
    printf("Equivalent binary value of decimal number %d: ",decimalNumber);
    for(j = i -1 ;j> 0;j--)
    printf("%d",binaryNumber[j]);
    return 0;
}

Q 7 - Which standard library function can return a pointer to the last occurrence of a character in a string?

A - stchar()

B - strrchr()

C - strchar() & stchar()

D - strrchar()

Answer : B

Explanation

The strrchr() function finds string for the last occurrence of a character and place the pointer to the last occurrence of character.

Q 8 - The return keyword used to transfer control from a function back to the calling function.

A - Yes

B - Switch

C - go back

D - goto

Answer : A

Explanation

In C, the return function stops the execution of a function and returns control with value to the calling function. Execution begins in the calling function by instantly following the call.

Q 9 - To print a double value which format specifier can be used?

A - %L

B - %lf

C - %Lf

D - None of the above

Answer : B

Explanation

Double value can be printed using %lf format specifier.

Q 10 - According to ANSI specification, how to declare main () function with command-line arguments?

A - int main(int argc, char *argv[])

B - int char main(int argc, *argv)

C -

int main()
{
   Int char (*argv argc);
)

D - None of the above

Answer : A

Explanation

Some time, it becomes necessary to deliver command line values to the C programming to execute the particular code when the code of the program is controlled from outside. Those command line values are called command line arguments. The command line arguments are handled by the main() function.

Declaration of main () with command-line argument is,

int main(int argc, char *argv[])

Where, argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program.

Advertisements