0

i was trying to paste c and 4 and expected output as c4 but can't follow the same , what is problem with my code

#include<stdio.h>
#define paste(a,b) (#a)##b
int main()
{
    printf("\n%s",paste(c,4));
    return 0;
}

Kanony
  • 509
  • 2
  • 12
  • You need a helper macro for the `#` "stringification". This is a FAQ, see the linked duplicate. – Lundin Mar 23 '21 at 09:02

1 Answers1

0
#include<stdio.h>
#define stringize(a) #a
#define paste(a,b) stringize(a##b)
int main()
{
    printf("\n%s",paste(c,4));
    return 0;
}

## concatinates parameters but # stringize a parameter and you cannot use them together like this: #define paste(a, b) #(a##b). That would give you an error

error: '#' is not followed by a macro parameter

Kanony
  • 509
  • 2
  • 12