C Language Learning Diary 4

Source: Internet
Author: User

Found a good learning video, called Teacher Zhu's IoT lecture hall.

1. Pointer type: When defining a pointer data type * Pointer name the data type of this place refers to the data type of the variable to which the pointer is pointing. Must match!

In the definition of the time can be defined as int *pint;  float *pfloat;  Char *pchar; Double *pdouble;

int *p; Understand the method, first see p, this is the variable name, and secondly, p is preceded by A *, indicating that the variable p is a pointer variable, and finally, *p in front of an int, indicating that the pointer variable p refers to an int type of data. Or can be written as int* p; When you understand it, you can think of int* as a whole, referring to a pointer to int type.

2. Pointers and Arrays

Array name: When you do an rvalue, the array name represents the first element of the array's first address, so you can assign a value directly to the pointer. If there is an int a[5], then A and &a[0] all represent the first address of the first element of the array a[0], PS: The first address of the first element of the array and the first address of the group are different. The former is the address of the array element, which is the first address of the array. The meanings are different but the values are the same.

Array by way of one visit: a[0] a[1] a[2] a[3] a[4]

The way the pointer is accessed once: *p * (p+1) * (p+2) * (p+3) * (p+4)

3, pointer + +--operation

The pointer itself is also a variable, so you can also perform operations. However, because the pointer variable itself is the address value of some other variable, it is meaningless to */% the value. The addition of two pointer variables is meaningless, the subtraction is meaningful, and the pointer variable +1,-1 is meaningful. +1 means that the pointer points to each other, and 1 means that the pointer is pointing to each other and move forward a grid.

*p++ can be regarded as * (p++) equivalent to *p;p+=1;

4. Using pointers in function-pass arguments

the int add (int a,int b) function parameter uses the INT function, and the argument copies its value once to the parameter, and itself does not participate in the calculation.

the int add (int *a,int *b) function argument passes the address so that the value of the argument variable can be changed inside the function

C Language Learning Diary 4

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.