What does #define a(c) mean? I see it used later as a(1); and a(2);
this is in c++ by the way
Its a preprocessor directive. You can name a constant or small function and use it in the program. During compile time the "varaible" will be replaced by the full expression
Something like `#define a(c) 3*c` is called a macro in C/C++. What happens when you compile your program is like Xavier said: any mention of `a(<whatever>)` will be replaced by `3*<whatever>`. So it is sort of a function call where the body of the function is copied to where you call the function (called inlining). Macros can be tricky if they're not written properly. What if you call something like `a(i+1)`. What you'd expect is something like `3*(i+1)`. But that's not what happens. Since macros are just copied/pasted without any knowledge of what is copied, what you'll end up with is this: `3*i + 1`. The best way to prevent things like that from happening is not to use macros, but use inline functions (which are safer). If you do want to use macros, put parenthesis around the parameters, like this: `#define a(c) 3*(c)`.
Join our real-time social learning platform and learn together with your friends!