Home » C programming language

Parameterized Macro - we cannot use space after the Macro Name



In the parameterized Macros, we cannot use space after the Macro Name while defining the Macro.

Consider this statement

#define SQUARE (N) (N*N)

In this statement, we are going to get square of a number, but this statement will produce an error because there is a space between SQUARE and (N), which is not allowed while defining a Parameterized Macro (function like macro).

Program with incorrect Macro Definition (with space between SQUARE and (N))

#include <stdio.h>

#define SQUARE (N) (N*N)

int main()
{
	printf("%d\n",SQUARE(10));
	return 0;
}

Output

    main.c:3:17: error: 'N' undeclared (first use in this function) 
     #define SQUARE (N) (N*N)
      ^ 
    main.c:7:16: note: in expansion of macro 'SQUARE'
      printf("%d\n",SQUARE(10));
     ^  
    main.c:3:17: note: each undeclared identifier is reported 
    only once for each function it appears in 
     #define SQUARE (N) (N*N)
      ^ 
    main.c:7:16: note: in expansion of macro 'SQUARE'
      printf("%d\n",SQUARE(10));

Program with correct Macro Definition (without space between SQUARE and (N))

#include <stdio.h>

#define SQUARE(N) (N*N)

int main()
{
	printf("%d\n",SQUARE(10));
	return 0;
}

Output

    100





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.