Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Kind Of Macro Is this?

Tags:

c++

c

I came across this following code:

#include<stdio.h>
#define d(x) x(#x[3])
int main(){
d(putchar);
}

Which prints c as the output. I wonder what does the macro #define d(x) x(#x[3]) does? In C language is there an operator like #? I can see this inside the macro body i.e here x(#x[3]). According to my normal eye it looks something different I see in C language but actually What does this does?

Edit : Whats the real use of # in real world?

I'm a novice in C and it will be good if the explanation is in simple terms. Thanks in advance.

like image 745
Ant's Avatar asked Sep 28 '11 15:09

Ant's


People also ask

What are the macro?

Well, “macro” is short for macronutrient. What's a macronutrient? They're the three categories of nutrients you eat the most and provide you with most of your energy: protein, carbohydrates and fats. So when you're counting your macros, you're counting the grams of proteins, carbs or fat that you're consuming.

What are the 7 types of macronutrients?

These are carbohydrates, proteins, fats, vitamins, minerals, fibre and water. It is important that everyone consumes these seven nutrients on a daily basis to help them build their bodies and maintain their health.


1 Answers

The character '#' is a stringizer -- it turns a symbol into a string. The code becomes

putchar("putchar"[3]);

like image 185
Laurion Burchall Avatar answered Sep 25 '22 23:09

Laurion Burchall