1,
# Define Sq (y) * (y) # include <iostream. h> void main () {int A, SQ; cout <"input a number:"; CIN> A; sq = SQ (a + 1 ); cout <"sq =" <sq <Endl ;}
When you enter 2, you can see the result:
2,
# Define Sq (y) y * y # include <iostream. h> void main () {int A, SQ; cout <"input a number:"; CIN> A; sq = SQ (a + 1 ); cout <"sq =" <sq <Endl ;}
When you enter 2, you can see the result:
3,
# Define Sq (y) * (y) # include <iostream. h> void main () {int A, SQ; cout <"input a number:"; CIN> A; sq = 16/Sq (a + 1 ); cout <"sq =" <sq <Endl ;}
When you enter 3, you can see the result:
4,
# Define Sq (y) * (y) # include <iostream. h> void main () {int A, SQ; cout <"input a number:"; CIN> A; sq = 16/Sq (a + 1 ); cout <"sq =" <sq <Endl ;}
When you enter 3, you can see the result:
The reason for the different results is that the string replacement in the macro definition only performs symbol replacement instead of other processing.
In 1: sq = (a + 1) * (a + 1 );
2: sq = a + 1 * A + 1;
3: sq = 16/(a + 1) * (a + 1 );
4: sq = 16/Sq (3 + 1) * (3 + 1 ));