C Language Learning 003: Hello pointer, language learning 003

Source: Internet
Author: User

C Language Learning 003: Hello pointer, language learning 003
Reasons for using pointers in C

This prevents a copy from passing data references only when calling a function.

Data sharing two pieces of code can operate on the same copy of data at the same time, instead of two independent copies

Read and Write Data Using pointers
# Include <stdio. h> int main () {int x = 5; printf ("x lives at % p \ n", & x ); // % p format operator outputs the address in hexadecimal format int * address_of_x = & x; // use the pointer variable to save the address int value of x = * address_of_x; // use the * operator to obtain the value printf ("% I \ n", value) pointed to by the pointer address; * address_of_x = 10; // change the value of the space pointed to by address_of_x address printf ("After the change, x = % I \ n", x); return 0 ;}
Captain, sail east!
# Include <stdio. h> void go_south_east (int * lat, int * lon) {// use the * operator to find the space corresponding to the lat address * lat = * lat-1; * lon = * lon + 1;} int main () {int latitude = 32; int longtitude =-64; go_south_east (& latitude, & longtitude ); // The address for transferring the variable printf ("Avast! Now at: [% I, % I] \ n ", latitude, longtitude); return 0 ;}

 

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.