0

Can anyone explain this code please ?

#include<stdio.h> #define macro(r,a,b) b##a##r #define CHAOS macro(r,a,b) void CHAOS(int n){printf("%d",n);} int main(){     bar(4);     bar(2);     return 0; }  

28th Jul 2021, 6:29 AM
Nipuna Bhanuka Hettiwatta
Nipuna Bhanuka Hettiwatta - avatar
1 Antwort
0
#define is a pre-processor directive first CHOAS is replaced by macro(r,a,b) Again we have another #define it replaces macro(r,a,b) by b##a##r ## acts as token pasting operator So b##a##r=bar Hence void CHOAS(int n) is void bar(int n) bar(4);//outputs 4 bar(2);//outputs 2 So,final output is 42 // From old post
28th Jul 2021, 8:47 AM
A S Raghuvanshi
A S Raghuvanshi - avatar