What is prefix and postfix? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What is prefix and postfix?

3rd Aug 2016, 12:11 PM
Navenkumar
Navenkumar - avatar
4 Answers
+ 3
adds 1 to variable ++x prefix x++ postfix example prefix adds 1 to x then copy value to y x=4 y=++x //x=5 y=5 postfix copy x value to y then adds 1 to y x=4 y=x++ //x=4 y=5 works with + - / *
3rd Aug 2016, 11:16 PM
IIder LLldwa
IIder LLldwa - avatar
+ 1
operators are written before the operand is known as prefix. eg. *AB(multiply A and B) operators are written after the operand is known as postdoc. eg. AB+(Add A, B)
3rd Aug 2016, 3:27 PM
Sayyed Firoz
Sayyed Firoz - avatar
0
There are increment operator (++) or decrement operator(--). As you can see below:- If you put increment operator before a variable. e.g: ++a; Then, it is an example of prefix. Else, if you put increment operator after a variable . e.g: a++; Then, this will become an example of postfix. NOTE: Same is for decrement operator(--) also.
6th Aug 2016, 10:22 AM
Akshay Khandka
Akshay Khandka - avatar
- 1
prefix and postfix are unary operators in c++ when you write i++ in loop it is known as postfix notation and when you write ++i it is known as prefix notation eg:- for (int i=0;i <9;i++) it is(i++) is postfix notation and you can use them at other places also to increment decrement value of variables etc.
3rd Aug 2016, 7:27 PM
sachin tomar
sachin tomar - avatar