Basic course of C language (ii) data types, variables, and operators (13)
Source: Internet
Author: User
Three, arrays and pointers
Arrays are closely related to pointers. The array name itself is the pointer to the array, which, in turn, can be viewed as an array, in which the array name and the pointer are essentially addresses, but the pointer is a variable and can be used as an operation. The array name is a constant and cannot be calculated.
For example:
Main ()
{
Char s[30], *p; /* Define character array and pointer variable * *
P=s; /* Pointer P point to the first element of array s s[0] address * *
.
.
.
* (P+8); /* Pointer P point to the 9th element of array s s[8] address * *
.
.
.
}
The above example shows that the array and the pointer have the following relationship:
(p+i) =& (S[i])
* (P+i) =s[i]
Therefore, the above expression can be used to exchange pairs of arrays and pointers. The difference between the two is that the array s is the program automatically allocates the required storage space for it, while the pointer P uses the dynamic division function to allocate storage space for it or assign it an assigned space address.
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