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 and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.