C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - Find Output of Program (Q.No. 4)
4.
What will be the output of the program?
#include<stdio.h>
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
char *str1="India";
char *str2="BIX";
JOIN(str1, str2);
return 0;
}
Discussion:
35 comments Page 4 of 4.
Kundan said:
1 decade ago
I agree with Natasa. For better understanding purpose I give a example code.
#include<stdio.h>
#define res(s1,s2) printf("%s=%d %s=%d",#s1,s1,#s2,s2);
void main()
{
int a=4,b=3;
res(a,b);
}
Output of this code is
a=4 b=3
#include<stdio.h>
#define res(s1,s2) printf("%s=%d %s=%d",#s1,s1,#s2,s2);
void main()
{
int a=4,b=3;
res(a,b);
}
Output of this code is
a=4 b=3
Saurabh Tiwari said:
1 decade ago
Yup.... arun and puja both of you are right because
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
Here
1) #s1 is equal to "variable name" i.e (str1) so it will print same as it is.
2) s1 that will print the "value of str1" i.e (India along with =)
and so on.
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
Here
1) #s1 is equal to "variable name" i.e (str1) so it will print same as it is.
2) s1 that will print the "value of str1" i.e (India along with =)
and so on.
Vimala said:
1 decade ago
# defines that name of the variable.
Durga dutt said:
1 decade ago
isn't an error if we use ";" at the end of macro expansion?
Nachiyappan said:
2 decades ago
Is it possible to print value through pre-processor ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers