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 3 of 4.
Gaurav Kumar Garg said:
1 decade ago
@Sachin Kumar.
Its your choice you can also remove semicolon. without semi colon it will also work.
With semi colon in macro
You can also call JOIN(str1, str2) <--- no semicolon.
Its your choice you can also remove semicolon. without semi colon it will also work.
With semi colon in macro
You can also call JOIN(str1, str2) <--- no semicolon.
Avinash said:
1 decade ago
# symbol is used to print the actual arguments that are passed to function.
Sunil Kothari said:
1 decade ago
#include<stdio.h>
#define cube(x) (x*x*x)
void main()
{
int a,b =3;
a= cube(++b);
printf("%d \n %d", a, b);
}
Output:
-------
150
6
Please explain above program?
#define cube(x) (x*x*x)
void main()
{
int a,b =3;
a= cube(++b);
printf("%d \n %d", a, b);
}
Output:
-------
150
6
Please explain above program?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers