Objective type (MCQ) questions on C programming language Part 3

 C programming language multiple type questions for exams point of view 

Basic C programming MCQ


1) What is the 16-bit compiler allowable range for integer constants?

  1. -3.4e38 to 3.4e38
  2. -32767 to 32768
  3. -32668 to 32667
  4. -32768 to 32767

Explanation: In a 16-bit C compiler, we have 2 bytes to store the value.

  • The range for signed integers is -32768 to 32767.
  • The range for unsigned integers is 0 to 65535.
  • The range for unsigned character is 0 to 255.

2) Study the following program:

main()  
{printf("mskuthar");  
main();}  

What will be the output of this program?

  1. Wrong statement.
  2. It will keep on printing mskuthar.
  3. It will Print mskuthar once.
  4. None of the these.

Answer: (b) It will keep on printing mskuthar.

Explanation: In this program, the main function will call itself again and again. Therefore, it will continue to print mskuthar.


3) What is required in each C program?

  1. The program must have at least one function.
  2. The program does not require any function.
  3. Input data
  4. Output data

Explanation: Every C program contains at least one function, and even the simplest programs can have additional functions specified. A function is a code snippet. In other words, it functions similarly to a sub-program.


4) What will this program print?

main()  
{  
  int i = 2;  
  {  
    int i = 4, j = 5;  
     printf("%d %d", i, j);  
  }    
  printf("%d %d", i, j);  
}  
  1. 4525
  2. 2525
  3. 4545
  4. None of the these

Explanation: The inner value of the function will be printed first, followed by the outer value of the function, in this program.


5) Which of the following comment is correct when a macro definition includes arguments?

  1. The opening parenthesis should immediately follow the macro name.
  2. There should be at least one blank between the macro name and the opening parenthesis.
  3. There should be only one blank between the macro name and the opening parenthesis.
  4. All the above comments are correct.

Answer: (a) The opening parenthesis should immediately follow the macro name.


6) What is a lint?

  1. C compiler.
  2. Interactive debugger.
  3. Analyzing tool.
  4. C interpreter.

Explanation: Lint is a code analysis tool that looks for suspicious constructs, stylistic flaws, bugs, and programming faults in source code. Lint is a compiler-like application that parses C programming source files. It verifies the files' syntactic accuracy.


7) What is the output of this statement "printf("%d", (a++))"?

  1. The value of (a + 1)
  2. The current value of a
  3. Error message
  4. Garbage

Answer: (b) The current value of "a".


8) Study the following program:

main()  
{  
   char x [10], *ptr = x;  
  scanf ("%s", x);  
  change(&x[4]);  
}  
 change(char a[])  
 {  
   puts(a);  
 }  

If abcdefg is the input, the output will be

  1. abcd
  2. abc
  3. efg
  4. Garbage

9) Study the following program:

  1. main()  
  2. {  
  3.   int a = 1, b = 2, c = 3:  
  4.   printf("%d", a + = (a + = 3, 5, a))  
  5. }  

What will be the output of this program?

  1. 6
  2. 9
  3. 12
  4. 8

Explanation: It is an effect of the comma operator.

a + = (a + = 3, 5, a)

It first evaluates to "a + = 3" i.e. a = a + 3 then evaluate 5 and then evaluate "a".

Therefore, we will get the output is 4.

Then,

a + = 4

It gives 8 as the output.


10) What does this declaration mean?

int x : 4;  
  1. X is a four-digit integer.
  2. X cannot be greater than a four-digit integer.
  3. X is a four-bit integer.
  4. None of the these

Explanation: This means, "X" is a four-bit integer.


11) Why is a macro used in place of a function?

  1. It reduces execution time.
  2. It reduces code size.
  3. It increases execution time.
  4. It increases code size.

Explanation: Macro is used in place of a function because it reduces code size, and very efficient.


12) In the C language, the constant is defined _______.

  1. Before main
  2. After main
  3. Anywhere, but starting on a new line.
  4. None of the these.

Explanation: In the C language, the constant is defined anywhere, but starting on a new line.


13) How many times will the following loop execute?

for(j = 1; j <= 10; j = j-1)  
  1. Forever
  2. Never
  3. 0
  4. 1

14) A pointer is a memory address. Suppose the pointer variable has p address 1000, and that p is declared to have type int*, and an int is 4 bytes long. What address is represented by expression p + 2?

  1. 1002
  2. 1004
  3. 1006
  4. 1008

15) What is the result after execution of the following code if a is 10, b is 5, and c is 10?

If ((a > b) && (a <= c))  
        a = a + 1;  
else  
        c = c+1;  
  1. a = 10, c = 10
  2. a = 11, c = 10
  3. a = 10, c = 11
  4. a = 11, c = 11

16) Which one of the following is a loop construct that will always be executed once?

  1. for
  2. while
  3. switch
  4. do while

Explanation: During the do-while loop, the body of a loop is frequently run at least once. The condition is tested after the body has been conducted. If the condition is true, the loop's body will be executed; otherwise, control will be moved out of the loop.


17) Which of the following best describes the ordering of destructor calls for stack-resident objects in a routine?

  1. The first object created is the first object destroyed; last created is last destroyed.
  2. The first object destroyed is the last object destroyed; last created is first destroyed.
  3. Objects are destroyed in the order they appear in memory, the object with the lowest memory address is destroyed first.
  4. The order is undefined and may vary from compiler to compiler.

18) How many characters can a string hold when declared as follows?

char name[20]:  
  1. 18
  2. 19
  3. 20
  4. None of the these

19) Directives are translated by the

  1. Pre-processor
  2. Compiler
  3. Linker
  4. Editor

Explanation: The pre-processor is a macro processor in the C programming language that allows the programmer to alter the program before it is properly built (Before construction, pro-processor directives are implemented).


20) How many bytes does "int = D" use?

  1. 0
  2. 1
  3. 2 or 4
  4. 10

Explanation: The int type takes 2 or 4 bytes.


21) What feature makes C++ so powerful?

  1. Easy implementation
  2. Reusing the old code
  3. Easy memory management
  4. All of the above

22) Which of the following will copy the null-terminated string that is in array src into array dest?

  1. dest = src;
  2. dest == src;
  3. strcpy(dest, src);
  4. strcpy(src, dest);

Explanation: strcpy is a string function that is used to copy the string between the two files. strcpy(destination, source)


23) In the statement "COUT << "mskuthar" << end1;", end1 is a ___.

  1. Extractor.
  2. Inserter.
  3. Manipulator.
  4. Terminator.

Explanation: End1 is an I/O manipulator that takes effect in printing a new line '\ n' character and then flushing the output stream.


24) Each instance of a class has a different set of

  1. Class interfaces.
  2. Methods.
  3. Return types.
  4. Attribute values.

Explanation: Each instance of the class has a different set of attribute values



Post a Comment

Previous Post Next Post