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.
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.
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.
Saravana said:
8 years ago
# is called Stringizing operator, whatever you pass (here variable name ) is converted to String, so result come with the variable name.
(1)
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?
Shekar said:
1 decade ago
# operator stringrises the operand. For example #str1 is replaced by "str1" during compilation.
Sachin Kumar said:
1 decade ago
Can anyone explain me that why semi-colon(;) is used because we can't use semi-colon in macros ?
Shashwat said:
1 decade ago
We have to add semicolon either at the macro declaration or while calling macro.
Avinash said:
1 decade ago
# symbol is used to print the actual arguments that are passed to function.
Sparsh610 said:
1 decade ago
It only works in macros ?
Or we can print them in main function too ?
Or we can print them in main function too ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers