What will be printed as the result of the operation below:
#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5,y=10;
swap(x,y);
printf("%d%d",x,y);
}
What will be printed as the result of the operation below:
#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5,y=10;
swap(x,y);
printf("%d%d",x,y);
}
Jump to PostIt's fairly simple to just compile that and find out yourself. If you don't have a compiler you can translate the macro yourself to get the following source:
void main() { int x=5,y=10; x=x+y;y=x-y;x=x-y;; printf("%d%d",x,y); }
From that point it's just straight addition and subtraction. You …
It's fairly simple to just compile that and find out yourself. If you don't have a compiler you can translate the macro yourself to get the following source:
void main() {
int x=5,y=10;
x=x+y;y=x-y;x=x-y;;
printf("%d%d",x,y);
}
From that point it's just straight addition and subtraction. You should be able to compute that easy enough.
According my point of view if you want to know the output of this code then it is swaping process
so look below
x=5,y=10;
x=x+y;//x=5+10 now x value is 15
y=x-y;//y=15-10 now y value is 5
x=x-y;//x=15-5 now x value is 10
so it's simple swaping process guys
At the end you will be find value as
x=10 and y=5;
Thanks ..That's all
We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.