C Programming - C Preprocessor - Discussion
Discussion Forum : C Preprocessor - General Questions (Q.No. 1)
1.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
int x=10, y=20;
SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}
Answer: Option
Explanation:
The code won't compile since declaration of t cannot occur within parenthesis.
Discussion:
25 comments Page 3 of 3.
Vishwadeep dubey said:
1 decade ago
#include<stdio.h>
int c,t;
#define SWAP(a,b,c) (t=a,a=b,b=c)
int main()
{
int x=10,y=20;
SWAP(x,y,t);
printf("x=%d,y=%d\n",x,y);
return 0;
}
Above program works correctly and swap the value of x and y.
int c,t;
#define SWAP(a,b,c) (t=a,a=b,b=c)
int main()
{
int x=10,y=20;
SWAP(x,y,t);
printf("x=%d,y=%d\n",x,y);
return 0;
}
Above program works correctly and swap the value of x and y.
(5)
Kumaran said:
1 decade ago
(c t; t=a, a=b, b=t) please explain this.
(1)
Anup singh said:
9 years ago
Hey, friends. Can anyone explain me the header file? Please.
#include
And why it is written in this bracket < >?
#include
And why it is written in this bracket < >?
(1)
Ganga said:
9 years ago
Why the swap is in header file. We can use the Capital letters when writing the c programme? Please tell me.
(1)
Rahul Sharma said:
9 years ago
@Ganga.
You can use small letters.
When you are define the small letters in above programme.
You can use small letters.
When you are define the small letters in above programme.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers