in DS edited by
753 views
0 votes
0 votes
#include <stdio.h>
#define foo(a,b) #b
int main(void) {
    int a=10,b=15,ab=20;
    // your code goes here
    printf("%d",ab+foo(a,b));
     return 0;
}


 
What is the output?

in DS edited by
753 views

2 Answers

1 vote
1 vote

Output is some random integer
ab is integer but foo(a,b) is string string + integer = God knows
Thing is    #define foo(a,b) #a     
means you are converting argument a into string   # here is stringify operator  
e.g : if u write  printf("%s",foo(ohyeah,b));
this will make a = ohyeah in  #define foo(a,b) #a    
and then #a  = #ohyeah    which means ohyeah is now a string which will replace foo(ohyeah,b)

I hope you got this if not lemme know :)

edited by
by

4 Comments

That means #b returns a pointer value of b it isn't return 'b' right?
1
1
it returns string means base address of string is returned
In any place where string is returned or it exist it means we are reffering its base address
in above scenario  ab + "a"  for %d  means ab + base adr(a)
2
2
Okay!
0
0
0 votes
0 votes
It should be a#b rather than #b acc to me.# is used to concatenate a & b.So it should be like 1015+20= 1035.Plz correct me if I am wrong.

Related questions