Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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

#include<stdio.h>

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

A - Compile error

B - Hi

C - HelloHi

D - Compiler warning

Answer : A

Explanation

compile error, keyword break can appear only within loop/switch statement.

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

#include<stdio.h>

main()
{
   int i = 1;
   
   while(++i <= 5)
      printf("%d ",i++);
}

A - 1 3 5

B - 2 4

C - 2 4 6

D - 2

Answer : B

Explanation

2 4, at while first incremented and later compared and in printf printed first and incremented later

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

#include<stdio.h>

main()
{ 
   int a[3] = {2,,1};
   
   printf("%d", a[a[0]]); 
}

A - 0

B - 1

C - 2

D - Compile error

Answer : D

Explanation

Compile error, invalid syntax in initializing the array.

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

#include<stdio.h>

void f(int a[])
{  
   int i;
   
   for(i=0; i<3; i++)
      a[i]++;
}
main()
{	
   int i,a[] = {10, 20, 30};
   
   f(a);
   for(i=0; i<3; ++i)
   {
      printf("%d ",a[i]);
   }
}

A - 10 20 30

B - 11 21 31

C - Compile error

D - Runtime error

Answer : B

Explanation

Arrays are always passed by reference.

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

#include<stdio.h>

int main();
void main()
{
   printf("Okay"); 
}

A - Okay

B - No output

C - Compile error. We cannot declare main() function.

D - Compile error. Mismatch in declaration & definition.

Answer : D

Explanation

Its compile error as the declaration of main() mismatches with the definition.

Q 6 - In Windows & Linux, how many bytes exist fornear, farandhugepointers?

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

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

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

D - near: 4, far: 5, huge: 6

Answer : B

Explanation

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

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

Q 7 - In Decimal system you can convert the binary number1011011111000101very easily.

A - Yes

B - Hexadecimal system

C - Octal system

D - Both, Octal & Decimal

Answer : B

Explanation

Hexadecimal is also known ashexorbase 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 the given below code, the functionfopen()uses "r"to open the file source.txt in binary mode for which purpose?

#include<stdio.h>

int main ()
{
   FILE *fp;
   
   fp = fopen("source.txt", "r");
   return 0;
}

A - For reading

B - For reading and writing

C - For creating a new file "source.txt" for reading

D - For creating a new file "source.txt" for writing

Answer : A

Explanation

To open a file in C programming, we can use library function fopen(). In the given above code, fopen() function is opening a file source.txt for reading. Here, r stands for reading. If, fopen() function does not find any file for reading, returns NULL

#include<stdio.h>

int main ()
{
   FILE *fp;
   
   fp = fopen("source.txt", "r");
   return 0;
}

Answer : B

Explanation

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

Q 10 - The maximum combined length of the command-line arguments as well as the spaces between adjacent arguments is a) 120 characters, b) 56 characters, c) Vary from one OS to another

A - a

B - a, b

C - a, b, c

D - c

Answer : D

Explanation

The maximum combined length of the command-line arguments and the spaces between adjacent arguments vary from one OS to another.

Advertisements