C language pointer and address

Source: Internet
Author: User

1. How to exchange values of two numbers

Void swap (int * a, int * B)

{

Int TEP = * A; // * A is actually the value of primary function a, and a is the address of primary function a's value.

* A = * B;

* B = TEP;

}

2. How to sort two-dimensional array Functions

Void DESC (INT (* A) [10], int I ){

// In this way, you can directly use the [I] [J] operation in this function, just like in the main function.

// Int (* A) [10] indicates a two-dimensional array with 10 columns. Then, write DESC (A, 5) in the main function ), this is a two-dimensional array with 5 rows.

For (INT n = 0; n <5; n ++)

For (Int J = 0; j <10; j ++)

{

If (a [n] [J] <a [n] [J + 1]) // you can determine the size. If the size is small, you can change the position of the backend.

Swap (& A [I] [J], & A [I] [J + 1]); // call the previous function to implement value exchange. Here is the address passed in, not a value.

}

 

}

* P: the number of pointers is the same. The number of (n-1) * after the first pointer is the address. Only the first pointer represents the pointer.

* ** P actually points to an address.

 

}

Related Article

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.