General doubt in macro


if i am defining 100000000 with N ,n,a then it is showing error and if i change it to sat t then if i again use it in program then same error arises . please explain me about this concept.

@nirupama1 Can you explain your doubt a little more, what it seems to be incorrect from your code is you are trying to pass a macro to a function which is not possible.

can you please tell me where to use macros and where not?

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro.
Mainly we use them just as shortcut to someething we have defined.

For example:- #define f(i, k, n) for(int i=k; i<n; i++)
Here if we want to run a loop from 0 to 5, we can write:- f(i, 0, 5) cout<<i

1 Like

But why is it showing error if i am using N in giving size to a dynamic array or even static array? a[N ]

You are using N as a parameter to pass in a function. You can just directly use it anywhere in the code.

Also, if N is large something like 10^7 or 10^8 then it is not possible to create a local array, of that size, because for local variable size limit is around 10^6 and for global it is 10^8

1 Like

@nirupama1 please mark this doubt as resolved if i have answered all your queries otherwise you can ask.


in this code if i am using N as macro then it shows compilation error when i make an array of size N. But if i am not using it it as macro then there is no error.

@nirupama1 the problem is not with using a macro, it is syntax error, no need to write semi-colon ; after defining the macro.
For eg:-
Wrong way:- #define N 10;
Right way:- #define N 10

1 Like