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

#include<stdio.h>

main()
{	
    register int x = 5;

    int *p;
    p=&x;
    x++;
    printf("%d",*p);
}

A - Compile error

B - 5

C - 6

D - Garbage value

Answer : A

Explanation

Compile error, we cannot take the address of a register variable.

Q 2 - What is the value of y for the following code snippet?

#include<stdio.h>

main()
{
   int x = 1;
   
   float y = x>>2;
   
   printf( "%f", y );
}

A - 4

B - 0.5

C - 0

D - 1

Answer : C

Explanation

0, data bits are lost for the above shift operation hence the value is 0.

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 = "Hello";
   
   while(*s!=NULL)
   printf("%c", *s++);
}

A - Hello

B - Helloellolloloo

C - ello

D - Compile error

Answer : A

Explanation

NULL is equivalent to \0 in value. Statement *s++ prints the character first and increments the address later.

Answer : B

Explanation

Prototype of a function can be used to declare a function. It is necessary in order to provide information (return type, parameter list and function name, etc) about the function to the compiler.

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 - How many times the given below program will print "IndiaPIN"?

#include<stdio.h>

int main ()
{
   printf("IndiaPIN");
   main();
   return 0;

}

A - Unlimited times

B - 0 times

C - 100 times

D - Till stack run over

Answer : D

Explanation

Astack over flowcomes when over loaded memory is used by the call stack. Here, main()functionis called repeatedly and its return address stores in the stack. When stack memory get filled, it displays the error stack overflow.

#include<stdio.h>

int main ()
{
   printf("IndiaPIN");
   main();
   return 0;

}

Q 9 - In C, what is the correct hierarchy of arithmetic operations?

A - */ + -

B - * +- /

C - / *+ -

D - + - / *

Answer : C

Explanation

In C, there are 5 arithmetic operators (+, -, *, /, and %) that can be used in performing arithmetic operations.

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