Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A few C functions I need help with

Name: OP 2012-04-30 4:57

These are pretty trivial, but I am no programmer.


if I do swap( 4, 6 )

where

int swap( int x, int y) {
   x = y;
   y = x;
   return( y );
}

What will it return and why?

Name: Anonymous 2012-04-30 10:02

x will become 6, y will be redundantly assigned to 6, 6 will be returned

what you should do instead is this

void swap(int x, int y){
    int t=x; 
    x=y;
    y=t;
}

preferably written on a single line since it is such a simple function, like this
void swap(int x, int y){int t=x; x=y; y=t;}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List