Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 34 - 35 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 34

C & C Plus Plus
Edit

Write in Short

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

Explanation

  • The evaluation is by popping out from the stack.
Table Shows the Program
int i = 5;Here define the integer variable i = 5
printf ( “% d % d % d % d % d % d” i ++ , i-, ++ i, -i, i) ;Print the all values of i

The arguments in a function call are pushed into the stack from left to right.

First value in stack top to bottom is ii = 5
Second value in stack is -i-i = 4
Third value in stack is ++ i++ i = 5
Fourth value in stack is i-i-= 5
Fifth value in stack is i ++i ++ = 4
  • And the evaluation is from right to left
  • So the answer is 45545.

Question 35

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     registeri =5;
  5.     charj[] =“hello” ;printf ( “%s %d” j, i);
  6. }

Explanation

  • In the program
Table Shows the Program
register i = 5;i value may be stored either in register or in memory
char j [] = “hello” ;j is a character array
printf ( “% s % d” j, i) ;
  • printf ( “% s” , j) ; prints hello 5
  • J is a array containing base address of first element of array.
  • Register i treated simple integer
  • So the answer is hello 5.

Developed by: