Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
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

Home » C programs » C preprocessor programs

Macro Arguments Evaluation in C



Macro Arguments Evaluation in C: Here, we will learn how Macro arguments evaluate in C programming language?
Submitted by IncludeHelp, on September 07, 2018

We can define a function like Macro, in which we can pass the arguments. When a Macro is called, the Macro body expands or we can say Macro Call replaces with Macro Body.

Now, the important thing is that: How Macro arguments evaluate? - "Macro arguments do not evaluate before Macro expansion, they evaluate after the expansion."

Consider the example:

#include <stdio.h>

#define CALC(X,Y) (X*Y)

int main()
{ 
	printf("%d\n",CALC(1+2, 3+4));
	return 0;
}

Output

11

Explanation:

If you are thinking that 1+2 and 3+4 will be evaluated before the expansion and it will be expanded as 3*7 then, you are wrong.

The arguments evaluate after the call, thus Macro CALC(1+2,3+4) will be expanded as = (1+2*3+4) = (1+6+4) =(11).

Finally, the output will be 11.






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



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 (2015-2018), Some rights reserved.