C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

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

COMMENTS