#Previous question #Index of C++ Questions #Next question

Differences are:

  1. Macro cannot check the data type of arguments,
  2. If parameters of any macro are given with operators ++ and -- with it and the macro used this argument more than one times then the increment or decrement of the original variable will that much times.
  3. Macros are expanded by the preprocessor and then compilation takes place. Compiler will refer error messages in expanded macro or the line where macro has been called.


Case 1:
T swap(T &a, T &b)
int a = 10;
float b = 12.2f;
We can never give swap(a, b); as a and b are of different type.
Case 2:
Extern int current_user;
Extern int next_user;
#define set_userid(x)\
current_user = x; \
next_user = x + 1; 
Int user = 10;
current_user = x++; 
next_user = x++ + 1; 
current_user = 10; 
next_user = 12; 
user = 12;
Case 3:
Line:1:#define set_userid(x)\
Line:2:current_user = x \
Line:3:next_user = x + 1; 
Line:4:int main (int argc, char *argv[])
Line:6:  int user = 10;
Line:7:  set_userid(user);
main.c(7):error C2146: syntax error : missing ';' before identifier 'next_user'
Line 2 has the original compilation error

You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.

Most popular topics (must visit)

Useful links for students