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() 
{ 
   int const 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() 
{ 
   int const a = 5; 
   
   a++; 
   printf(“%d”,a); 
} 

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

#include<stdio.h>

main()
{   
   int r, x = 2;
   float y = 5;

   r = y%x;
   printf("%d", r); 
}

A - 1

B - 0

C - 2

D - Compile error

Answer : D

Explanation

Compile Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

Answer : B

Explanation

(b). Compilation is the process of translating high level language statements into equivalent machine code, which is object code.

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

#include<stdio.h>

int* f() 
{
   int x = 5;
   
   return &x;
}	
main() 
{
   printf("%d", *f());
}

A - 5

B - Address of ‘x’

C - Compile error

D - Runtime error

Answer : D

Explanation

It is invalid to return local variable address as the local variable gets removed after the functions execution is completed.

Q 5 - What is the built in library function to compare two strings?

A - string_cmp()

B - strcmp()

C - equals()

D - str_compare()

Answer : B

Explanation

strcmp() is the built in function from “string.h” to compare two strings. Returns 0 if both are same strings. Returns -1 if first < second string. Returns 1 first > second.

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 - 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.

Answer : A

Explanation

randomize() picks the current time value as the SEED number to generate random numbers.

Answer : A

Explanation

Unary operator acts on single expression.

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