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.
Neeraja said:
1 decade ago
Please give clarity what #s1 #s2 means?
Shashwat said:
1 decade ago
We have to add semicolon either at the macro declaration or while calling macro.
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?
Avinash said:
1 decade ago
# symbol is used to print the actual arguments that are passed to function.
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.
Nandini said:
1 decade ago
#is name of the variable. So, if #str1 gives str1 content.
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 ?
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 ?
Durga dutt said:
1 decade ago
isn't an error if we use ";" at the end of macro expansion?
Vimala said:
1 decade ago
# defines that name of the variable.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers