Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.

Similar presentations


Presentation on theme: "Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable."— Presentation transcript:

1 Pointers as arrays C++ Programming Technologies

2 Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable in many cases. For example, a pointer that points to the beginning of an array can access that array by using either pointer arithmetic or array-style indexing. Pointers are the variables that hold address. Pointers can point at cells of an array not only single variable.

3 Example:

4 Pointer ’ s size in bytes Suppose, pointer needs to point to the fourth element of an array, that is, hold address of fourth array element in above case. Since ptr points to the third element in the above example, ptr + 1 points to the fourth element. You may think that, ptr + 1 may hold the address of byte next to ptr. But it's not correct. It is because pointer ptr is a pointer to int and size of int is fixed for a operating system (size of int is 4 byte of 64-bit operating system). Hence, the address between ptr and ptr + 1 differs by 4 bytes. If pointer ptr was pointer to char then, the address between ptr and ptr + 1would have differed by 1 byte since size of a character is 1 byte.

5

6

7

8

9

10

11 THANKS FOR ATTENTION


Download ppt "Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable."

Similar presentations


Ads by Google