Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does # sign mean in C?

Tags:

c

I have come across this code and I am not sure what #regis doing:

#define FPGA_WRITE(reg,val) do { printf("%-20s %08X <<- %08lX\n", #reg, (reg), (unsigned long)(val));} while (0)

int main()
{
   FPGA_WRITE(10,15);
   return 0;
}

This prints this following:

10                   0000000A <<- 0000000F

If I take out the #, I get a segfault when I execute the code. Strange. What is the usage of #?

like image 306
Sedmaister Avatar asked Sep 25 '18 21:09

Sedmaister


1 Answers

It is Stringizing Operator (#) used inside #define pre-processor macros,
which turns the argument it precedes into a quoted string

like image 156
Mayur Avatar answered Oct 16 '22 02:10

Mayur