C Language Basics Tutorial (iv) Pointers, structures, unions, and enumerations (3)

Source: Internet
Author: User
Tags arrays
1.2. Address operation
The methods allowed by pointers are:
(1). The pointer under certain conditions, can be compared, here is a certain condition, refers to two pointers to the same object is meaningful, for example, two pointer variable p,q point to the same array, then, >=, <=, = = and other relational operators are normal. If P==q is true, it means that p, Q points to the same element of the array; if P<q is true, the array element that P points to is preceded by the array element that Q points to (the pointer to the array element is discussed in detail below).
(2). Pointers and integers can be added and reduced. To set p to be a pointer to an array element, to the No. 0 element of the array at the start, and to an integer of N, then p+n represents the nth element (the element labeled N) that points to the array.
Regardless of what type of data the pointer variable points to, pointers and integers to add and subtract operations, the compiler always according to the object's data length to n amplification, on the general computer, the char amplification factor is 1,int, the short amplification factor is 2,long and the float amplification factor is 4, The double magnification factor is 8. This principle is also adhered to in relation to the structure or union described below.
(3). Two pointer variables under certain conditions, can be subtraction operation. If p, Q points to the same array, the absolute value of the P-Q represents the number of elements between the object referred to by P and the object referred to by Q. The result of its subtraction follows the rule of narrowing the byte length of the object type.
2. Pointers and Arrays
Pointers and arrays are closely related, and any action that can be done by the array's subscripts is also available with pointers, but using pointers in your program makes your code more compact and flexible.
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.