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 following code snippet?

#include<stdio.h>

main() 
{
   int x = 5;
   
   if(x=5)
   {	
      if(x=5) printf("Hello");
   } 
   printf("Hi");
}

A - HelloHi

B - Hi

C - Hello

D - Compiler error

Answer : A

Explanation

HelloHi, both the if statement’s expression evaluates to be 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()
{	
   union abc {
      int x;
      char ch;
   }var;

   var.ch = 'A';
   printf("%d", var.x);
}

A - A

B - Garbage value

C - 65

D - 97

Answer : C

Explanation

65, as the union variables share common memory for all its elements, x gets ‘A’ whose ASCII value is 65 and is printed.

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

#include<stdio.h>

main()
{	
   int a[] = {10, 20, 30};
   
   printf("%d", *a+1);
}

A - 10

B - 20

C - 11

D - 21

Answer : C

Explanation

*a refers to 10 and adding a 1 to it gives 11.

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

#include<stdio.h>

void main()
{
   char *s = "C++";
   
   printf("%s ", s);
   s++;
   printf("%s", s);
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : B

Explanation

After s++, s points the string “++”.

Answer : A

Explanation

In C programming, NULL indicates the value 0 of a pointer, which means; pointer that initializes with NULL value considered as NULL pointer.

Q 7 - In Decimal system you can convert the binary number 1011011111000101 very easily.

A - Yes

B - Hexadecimal system

C - Octal system

D - Both, Octal & Decimal

Answer : B

Explanation

Hexadecimal is also known as hex or base 16. It is a system help in writing and presenting numerical values. Binary (base 2) is a popular numeral system (represent numbers by just two digit values “0 and 1”), used to present the language of computers. Hexadecimal system can easily convert those numbers.

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.

Answer : B

Explanation

As per the operators preference.

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