Preprocessor c++ made easy

#include "stdafx.h"
#include<iostream>
using namespace std;
#define SQUARE(X) (X)*(X) //macro to calculate square of a number
#define PR(X) cout<<"The result is: "<<X<<"\n"<<endl; //macro for printing result on screen
int main(void)
{
int x = 4;
int z;
z = SQUARE(x); //z is equal of square of 4
PR(z);
z = SQUARE(2); //z is equal of square of 2
PR(z);
PR(SQUARE(x+2)); //calculating and printing result without storing result in z
PR(100/SQUARE(2));
cout<<"x is "<<x<<"\n"<<endl;
PR((SQUARE(x++)));
cout<<"After incrementing, x is: "<<x<<"\n"<<endl;
}


Previous
Next Post »

Comments:

Disqus Shortname