Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the # operator do in macros? [duplicate]

Tags:

c

macros

#include <stdio.h>

#define foo(x, y) #x #y

int main()
{
    printf("%s\n", foo(k, l));
    return 0;
}

Output:
kl

I know that ## does concatenation. From the output it seems that # also does concatenation. Am I correct?

If I am correct then what is the difference between ## operator and # operator?

like image 317
Pankaj Mahato Avatar asked Oct 02 '22 16:10

Pankaj Mahato


1 Answers

# stringifies the parameter. See http://www.cs.utah.edu/dept/old/texinfo/cpp/cpp.html#SEC15

## concatenates strings. See http://www.cs.utah.edu/dept/old/texinfo/cpp/cpp.html#SEC16

like image 53
keshlam Avatar answered Oct 12 '22 22:10

keshlam