ch3-StringizingExpressions
Chapter_3 Exercise_3-24 DynamicDebugFlags | Exercise_3-31 Exercise_3-25 |
StringizingExpressions TCP1, p. 211-212 (stringizing_expressions.c, StringizingExpressions.cpp)
stringizing_expressions.c download
#include <stdio.h> // for printf()
// print `A' as an int:
#define P(A) printf("%s: %d\n", #A, A) // no semicolon here
int main()
{
int a = 1, b = 2, c = 3;
P(a); P(b); P(c); // semicolons
P(a + b); // here
P((c - a)/b);
return 0;
}
/*
g++ stringizing_expressions.c -o stringizing_expressions
./stringizing_expressions
a: 1
b: 2
c: 3
a + b: 3
(c - a)/b: 1
*/
StringizingExpressions.cpp download
#include <iostream>
using std::cout;
using std::endl;
#define P(A) cout << #A << ": " << (A) << endl // no semicolon here
int main()
{
int a = 1, b = 2, c = 3;
P(a); P(b); P(c); // semicolons
P(a + b); // here
P((c - a)/b);
return 0;
}
/*
g++ StringizingExpressions.cpp -o StringizingExpressions
./StringizingExpressions
a: 1
b: 2
c: 3
a + b: 3
(c - a)/b: 1
*/
Note: See also ch3-PointerArithmetic in Section ch3-Composite_Types.
Chapter_3 Exercise_3-24 DynamicDebugFlags | BACK_TO_TOP | Exercise_3-31 Exercise_3-25 |
Comments
Post a Comment