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 2 of 4.
Shashwat said:
1 decade ago
We have to add semicolon either at the macro declaration or while calling macro.
Neeraja said:
1 decade ago
Please give clarity what #s1 #s2 means?
Omkar said:
1 decade ago
Can anyone explain @Sunil's program ?
Bhushan said:
1 decade ago
@Sunil : It should be:
216.
6.
Value would be overwrite.
a = (++b * ++b * ++b).
a = (4 * ++b * ++b).
a = (5 * 5 * ++b).
a = (6 * 6 * 6).
a = 216.
216.
6.
Value would be overwrite.
a = (++b * ++b * ++b).
a = (4 * ++b * ++b).
a = (5 * 5 * ++b).
a = (6 * 6 * 6).
a = 216.
Nimisha said:
1 decade ago
#s is used to print string value.
Kaviyakarthi said:
10 years ago
@Sunil:
I thought the solution is,
a = ++b*++b*++b.
a = ++3*++b*++b.
a = 4*++4*++b.
a = 4*5*++5.
a = 4*5*6.
a = 120.
b = 6.
I thought the solution is,
a = ++b*++b*++b.
a = ++3*++b*++b.
a = 4*++4*++b.
a = 4*5*++5.
a = 4*5*6.
a = 120.
b = 6.
Kaviyakarthi said:
10 years ago
@Sunil:
I thought the solution is,
a = ++b*++b*++b.
a = ++3*++b*++b.
a = 4*++4*++b.
a = 4*5*++5.
a = 4*5*6.
a = 120.
b = 6.
I thought the solution is,
a = ++b*++b*++b.
a = ++3*++b*++b.
a = 4*++4*++b.
a = 4*5*++5.
a = 4*5*6.
a = 120.
b = 6.
Ashwini said:
8 years ago
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
How ?
please help me to understand it?
How ?
please help me to understand it?
Arun said:
1 decade ago
#s1,#s2 - this will print the variable name which has been declared with the join
s1,s2 - which will display the characters
str1 and str2 are the variables and *str1 and * str2 are the pointers which has declred as char.
s1,s2 - which will display the characters
str1 and str2 are the variables and *str1 and * str2 are the pointers which has declred as char.
Vasuuma said:
2 decades ago
# mean to variable name. so #s1 gives output as str1
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers