English
Tamil Nadu Board of Secondary EducationHSC Science Class 11

Assume n = 10; what will be result of n++ and --n;? - Computer Science

Advertisements
Advertisements

Question

Assume n = 10; what will be result of n++ and --n;?

Short Note

Solution

11 and 9 respectively.

the notations like n++ and ++n are used in coding

both n++ and ++n stand for n=n+1 but there is small difference.

if we assume a=10 and n=10 then a<++n is true but a<n++ is false.

for a<++n first n value gets increment by 1 and becomes 11 then the condition is checked.

for a<n++ first the condition is checked and becomes false then n is incremented by 1 and becomes 11.

- -n and n- - also explained in the same way but - - is decrement operator w3here as ++ is increment operator.

shaalaa.com
Lexical Units (Tokens)
  Is there an error in this question or solution?
Chapter 9: Introduction to C++ - Evaluation - Section - B [Page 131]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 11 TN Board
Chapter 9 Introduction to C++
Evaluation - Section - B | Q 5. | Page 131
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×