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.
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.
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.
The character '#' is a stringizer -- it turns a symbol into a string. The code becomes
putchar("putchar"[3]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With