Languages-C & C Plus Plus [TCS Placement]: Sample Questions 18 - 19 of 119

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 18

C & C Plus Plus

Describe in Detail


Can a variable be both constant and volatile?


  • 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 19

C & C Plus Plus

Write in Short

Short Answer▾

Which of the following operators is incorrect and why? (>= , <= , <> , ==)


  • “>=” indicates the operation “greater than or equal to” .
  • “<=” indicates the operation “less than or equal to” .
  • “<>” it doesn՚t have any operational meaning. Therefore it is incorrect in the C programming languages.
  • While this operator is correctly interpreted as “not equal to” in writing conditional statements, it is not the proper operator in C programming. Instead, the operator “! =” must be used for “not equal to” condition.
  • “==” this symbol is used to check whether two expressions or numbers are equal or not. Example: (x == 2) this expression implies that it checks whether x is equal to 2 or not and proceeds for further operation

Developed by: