Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 10 - 12 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 10

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main()
  2. {
  3.     Main();
  4. }

Explanation

  • Runtime error: stack overflow.
  • Main function calls itself repeatedly.
  • Each time the function is called its return address is stored in the call stack.
  • Since there is no condition to terminate the function call, the call stack overflows at runtime.
  • So it terminates the program and results in an error.

Question 11

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     inti =-1;
  4.     +i;
  5.     printf ( “i =%d, +i =%d” i, +i);
  6. }

Explanation

i =-1, + i =-1

In a program

Table Shows the Program
int i =-1;Define the integer variable i =-1.
+ i;
  • Apply unary operator
  • Unary + is the only dummy operator in C.
  • Ignore it as it has no effect in the expressions (hence the name dummy operator) .
printf ( “i =% d, + i =% d” i, + i) ;Print the i =-1 and + i =-1
Define the Unary Operator and How to Use in Expression

Question 12

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. main ()
  2. {
  3.     registerinta =2;
  4.     printf ( “Addressofa =%d” ,&a);
  5.     printf ( “Valueofa =%d”, a);
  6. }

Explanation

In this program

Table Shows the Program
register int a = 2;
  • Given the integer variable a = 2
  • And this variable also uses register keyword.
  • Registers are faster than memory access, so the variables which are most frequently used in c program can be put in registers using register keyword. It is only a hint to the compiler and not a gurantee
printf ( “Address of a =% d” , &a) ;& (address of) operator cannot be applied on register variables.

Developed by: