Renesas Technology, Tools FAQs
Last Updated: July 5, 2001
Document Number: 01062001_e
Q.
I made the following program in C.
if (x++ == 5){
aaasub();
}
Upon examining the generated codes, it seems that variable x (the operand) is compared with 5 before the variable increment. Is the
following description necessary in order to have variable x compared with 5 after the variable increment?
x++;
if (x ==5){
aaasub();
}
A.
There are two ways to use the increment (++) and decrement (--) operators: preceding the operand (pre-) or following the operand
(post-).
pre-increment / pre-decrement: Increment or decrement operator precedes the variable (the operand).
post-increment / post-decrement: Increment or decrement follows the variable (the operand).
The program you made uses a post-increment, and the comparison of variable x and 5 is performed before the variable increment.
To perform the desired operation, you have to use a pre-increment for variable x.
if (++x == 5){
aaasub();
}
Top of Page | Back to Previous Page
Terms of Use Privacy Policy
(C)2004 Renesas Technology Corp., All Rights Reserved.
Comentarios a estos manuales