void swap (int a,int b) can such a function prototype exchange two numbers? OK!!

Source: Internet
Author: User

Yesterday in the guidance of other people's hands, the whim of the idea of such a problem, I think it is very interesting, to everyone to see, although not a very advanced technology, but it is a very interesting idea .....

The title is:

void swap (int a,int b) This function prototype, can not use global variables and static variables in the case, how to achieve the exchange of two number?

If you are interested in thinking about it, just look at the answer below if you are not interested.


--------------------------------------------------Gorgeous split-line------------------------------------------------------



#include "stdafx.h" #include <iostream>void swap (int a,int b) {int c;c = * (int *) a;* (int *) A = * (int *) b;* (int *) B = C ;} int main (int argc, char* argv[]) {int a = 2,B = 3;swap (int) &a, (int) &b); Cout<<a<<b;system ("pause"); return 0;}


void swap (int a,int b) can such a function prototype exchange two numbers? OK!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.