336 views
0 votes
0 votes
#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);

}

Will the output be 10 5 or 5 10?

1 Answer

1 votes
1 votes

i hope you mistakenly split the preprocessor statements in multiple lines without using \

what i mean, you typed

#define swap(a,b)

a=a+b;b=a-b;a=a-b;
 

 instead of 

#define swap(a,b) \

a=a+b;b=a-b;a=a-b;
 

 

output is x and y are swapped... why swapped?

due to preprocessor just simply replace what you need

then your code look like as 

 

void main()

{

int x=5,y=10;

x=x+y;
y=x-y;
x=x-y;

printf("%d,%d",x,y);

}

 

therefore output is 10,5 

Related questions

0 votes
0 votes
1 answer
1
1 votes
1 votes
0 answers
2
srestha asked Mar 6, 2019
814 views
void find(int x){ static int i=10,y=0; y=y+i; for(i;i>0;i=i-10){ if(x!=0) find(x-1); else{ printf("%d",y); } } }What will be output printed for find(4)?
2 votes
2 votes
0 answers
4
srestha asked Mar 5, 2019
1,277 views
What will be output of the program?int d=0; int f(int a,int b){ int c; d++; if(b==3) return a*a*a; else{ c=f(a,b/3); return(c*c*c); } } int main(){ printf("%d",f(4,81)); ...