Subex Placement: Sample Questions 14 - 15 of 19

Doorsteptutor material for competitive exams is prepared by world's top subject experts: get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 14

Edit

Write in Short

Short Answer▾

What will be the value of y in the following code?

  1. main()
  2. {
  3.     intx =0,y =1;
  4.     if (x =y)
  5.     y =7;
  6.     else
  7.     y =2;
  8. }

Explanation

  • Here, in main () function two integer variables x and y are initialized by 0 and 1 respectively. In if statement assignment operator is placed between x and y. So, no condition will be checked.
  • Here it simply assigns the value of y into x and thus x and y posseses same value. As if condition is ssatisfied (i.e.. Both variable has same value) else part will not get executed and 7 will be stored in variable y.

Question 15

Edit

Write in Short

Short Answer▾

What will be the output of the following code?

  1. #definemax10
  2. main()
  3. {
  4.     printf("n%d",max++);
  5. }

Explanation

Here max is preprocessor macro symbol which process first before the actual compilation. First preprocessor replace the symbol to its value in entire the program before the compilation. So in this program max will be replaced by 10 before compilation. Thus program will be converted like this:

  1. main()
  2. {
  3.     printf(“n%d”,10++);
  4. }

This will generate error because we cannot assign constant value directly. Hence compiler will give error.

Developed by: