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

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

#include<stdio.h>

main() 
{ 
   const int a = 5; 
   
   a++; 
   printf("%d", a); 
}

A - 5

B - 6

C - Runtime error

D - Compile error

Answer : D

Explanation

Compile error - constant variable cannot be modified.

main() 
{ 
   const int a = 5; 
   
   a++; 
   printf("%d", a); 
}

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

#include<stdio.h>

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

A - 1

B - 1 2

C - No output

D - Compile error

Answer : B

Explanation

1 2, do..while is an entry control loop. As the expression x++ is post form loop continues for 2nd time also.

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

#include<stdio.h>

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

A - 0

B - 1

C - 2

D - Compile error.

Answer : C

Explanation

2, as ‘a’ refers to base address.

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

#include<stdio.h>

main() 
{
}

A - No output

B - Garbage

C - Compile error

D - Runtime error

Answer : A

Explanation

It is valid to have main() function empty, therefore producing no displayable output.

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 : D

Explanation

‘s’ refers to a constant address and cannot be incremented.

Q 6 - In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?

A - math.h

B - conio.h

C - dos.h

D - stdio.h

Answer : A

Explanation

math.h is a header file in the standard library designed for basic mathematical operations

Q 7 - Which header file supports the functions - malloc() and calloc()?

A - stdlib.h

B - memory.h

C - math.h

D - stdio.h

Answer : A

Explanation

void *malloc(size_t size) : Allocates the requested memory and returns a pointer to it.

void *calloc(size_t nitems, size_t size): Allocates the requested memory and returns a pointer to it.

Q 8 - Which library function can convert an unsigned long to a string?

A - ltoa() 

B - ultoa()

C - system() 

D - unsigned long can’t be converted to a string

Answer : B

Explanation

ultoa() - Convert an unsigned long integer into a string.

Q 9 - The correct order of evaluation for the expression “z = x + y * z / 4 % 2 – 1”

A - * / % = + -

B - / * % - + =

C - - + = * % /

D - * / % + - =

Answer : D

Explanation

* / % holds highest priority than + - . All with left to right associativity.

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.


cprogramming_questions_answers.htm

Advertisements