How to troubleshoot problems that cannot have multiple return values

Source: Internet
Author: User

C language can only have a return value, want to get multiple return values, do not want to or can't put them into an array, do not want to use global variables, we can use the reference pass (pass by reference) method.


For example, we have variables, a, B, we use a function to handle them at the same time, and then we return a and a, we can do this:

int a = 5;int B = 10;changeaandb (&a,&b);p rintf ("A is%d, and B is%d.\n", A, b);

Method Changeaandb:

void changeaandb (int *p1, int *p2) {int a = *P1;    int b = *P2;    *P1 = ++a;    *P2 =--b; *P2 =--*P2; There is no parentheses here, but if (*P2)--You must have parentheses}


In this way, we are actually changing the value of the corresponding address, so we do not return a value as a value pass.

How to troubleshoot problems that cannot have multiple return values

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.