TCS Placement: Sample Questions 62 - 63 of 502

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 62

Edit

Describe in Detail

Essay▾

Can a variable be both constant and volatile?

Explanation

  • Yes.
  • The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed from outside.
  • Consider the value of timer- The function itself might not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile.
  • If a variable is both const and volatile, the two modifiers can appear in either order.
  • This is used mostly in an embedded system.
  • As another example consider the Interrupt Status Register- a status register, program should not modify this variable so it should be a constant. But this variable can be changed by the processor or hardware based on the interrupt condition. So the program should read the value of this variable without any optimization and hence it should be declared as volatile.

Question 63

Edit

Write in Short

Short Answer▾

The sum of the digits of a two digit number is 8. When 18 are added to the number, the digits are reversed. Find the number?

Explanation

  • Let x be the unit digit in number and y be the ten՚s digit in the number.
  • So, number becomes 10y + x.
  • The sum of the digits of a number is 8, i.e..
  • When 18 are added to the number, the digits of the number are reversed, i.e.. number becomes 10x + y.
  • Writing this statement into equation form,

  • Equating both the equations,

  • Substituting the value of y in equation (i) ,
  • So, number becomes 35.

Developed by: