×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.