When defining macros, why do we have to give the value in the function?

For example, I did this -

#define pb push_back;

It gives error while this is correct -

#define pb(x) push_back(x);

Why so?

@mathecodician You are writing semicolon in the first macro definition which will give an error at the time of compilation. Preprocessor just replaces the macro-name with the text given in the code. It’s not necessary to give the value in the function when defining macros. Example:

#define pb push_back
vector<int> v;
int main(){
    int x=5;
1 Like