Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<stdio.h>
 void main( )
{ 
    int c,d;
    scanf("%d %d", &c, &d);
    printf("Value after swap c = %d and d = %d", d, c);
}


What I have tried:

Is the upper code is right or wrong?
Posted
Updated 7-Mar-22 5:43am

It looks good for display purposes, but the intention is probably to swap c and d for real:
C
int temp = c;
c = d;
d = temp;
 
Share this answer
 
Comments
Maciej Los 7-Mar-22 14:44pm    
5ed!
Or for extra snazzy points:
C
void main( )
    { 
    int c,d;
    scanf("%d %d", &c, &d);
    c ^= d;
    d ^= c;
    c ^= d;
    printf("Value after swap c = %d and d = %d\n", c, d);
    }

Now work out how it does that ...
 
Share this answer
 
Comments
Greg Utas 7-Mar-22 12:16pm    
LOL
Maciej Los 7-Mar-22 14:44pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900