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() 
{
   for(1;2;3)
      printf("Hello");
}

A - Infinite loop

B - Prints “Hello” once.

C - No output

D - Compile error

Answer : A

Explanation

infinite loop, as the second expression is non-0, hence the condition is always true.

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

#include<stdio.h>

void swap(int m, int n)
{
   int x = m;
   
   m = n;
   n = x;
}
main()
{
   int x=5, y=3;

   swap(x,y);
   printf("%d %d", x, y);
}

A - 3 5

B - 5 3

C - 5 5

D - Compile error

Answer : B

Explanation

5 3, call by value mechanism can’t alter actual arguments.

#include <stdio.h>
void swap(int m, int n)
{
   int x = m;
   
   m = n;
   n = x;
}
main()
{
   int x=5, y=3;

   swap(x,y);
   printf("%d %d", x, y);
}

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

#include<stdio.h>

main()
{
   int i = 1;
   
   Charminar:
   printf("%d ",i++);
   if(i==3) break;
   if(i<=5) goto Charminar;
}

A - 1 2

B - 1 2 3

C - 1 2 4 5

D - Compile error

Answer : D

Explanation

Compile error, wrong place for ‘break’ to appear.

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.

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 - 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 - In DOS, how many bytes exist for near, far and huge pointers?

A - Near: 2, far: 4, huge: 7

B - near: 4, far: 2, huge: 8

C - near: 2, far: 4, huge: 4

D - near: 4, far: 0, huge: 0

Answer : C

Explanation

In DOS, numbers of byte exist for near pointer = 2, far pointer = 4 and huge pointer = 4.

In Windows and Linux, numbers of byte exist for near pointer = 4, far pointer = 4 and huge pointer = 4.

Q 9 - In the given below code, what will be return by the function get ()?

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

A - 40

B - 20

C - 0

D - Error

Answer : A

Explanation

Firstly, “int get()” which is a get() function prototype returns an integer value without any parameters.

Secondly, const int x = get(); The constant variable x is declared as an integer data type and initialized with the value of get(). Hence, the value of get() is 40, printf("%d", x); will print the value of x, that means; 40. So, the program output will be 40.

#include<stdio.h>

int get();

int main()

{
   const int x = get();
   
   printf("%d", x);
   return 0;
}
   int get()
   {
    return 40;
}

Answer : D

Explanation

square parenthesis signify as array at declaration and type is char*, so array of character pointers.

Advertisements