Pointer Operations (c + +)

Source: Internet
Author: User

This article is to learn the "C + + Programming Tutorial-design ideas and implementation" notes.

Pointers can be added and reduced.

The array name itself, with no square brackets and subscript, is actually an address that represents the array start address.

The array name of an integer array gets an integer address, and the array name of the character array gets the one-character address.

The array start address can be assigned to a pointer and manipulated by moving the pointer (plus minus the pointer) to the group element.

For example: The following program uses pointer arithmetic to calculate the and of the array elements:

#include <iostream.h>
int main () {
int iarray[10];
int sum = 0;
int * Iptr = iarray;//is initialized with the array name IArray to the pointer
int *iptr;
Iptr = IArray; The two sentences are equal to the above sentence//iptr = &iArray[0]; This sentence is the same as the one on the left
for (int i = 0;i < 10;i++) {
Iarray[i] = i * 2;
cout<< "*iarray[" <<i<< "]" << "is" <<iArray[i]<<endl;
}
for (int idex = 0; Idex < idex++) {
sum + = *iptr;
cout<< "*iptr is" <<*iPtr<<endl;
iptr++;

}
cout<< "Sum is" <<sum<<endl;
}

Because the pointer is an address that has a data type, the pointer operation is expanded in the data type.

Pointer Operations (c + +)

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.