Pointers

Mindmapping notes on Pointers

Get Started. It's Free
or sign up with your email address
Rocket clouds
Pointers by Mind Map: Pointers

1. Declaration and syntax of Pointers

1.1. type *name - This is the command to declare pointer p of type integer.

1.2. p = &n; -This sets the value of variable p to the address of variable n.

1.3. *p = 5; if p = &n; then p = 5 sets the value of n to 5 this does NOT change the value of p itself

1.4. no casting double (*p) cannot be done. either is double (&n)

2. It's a variable whose value is the address of another variable.

2.1. similar to passing by reference in functions

2.2. adress in memory can be different every time for the pointer

2.3. address in memory is NOT assigned based on order of creation

3. Advantages and usage of Pointers

3.1. Pass large amounts of data without storing or copying

3.2. Allows to functions to directly manipulate the value held in the address, not just the copy of it

3.3. Advance programs allows creation of data structures with links

4. Hex // Binary // Decimal

4.1. 32-Bit (x86) Architecture - address are 32 binary wide - or 4 bytes, 8 nibble/hex wide - only about 4 billion addresses - limited to 4 GB memory

4.2. 64-Bit (x64) Architecture - address are 64 binary wide - or 8 bytes, 16 nibble/hex wide - practically unlimited address space

4.3. Hex Binary Decimal 4 0100 4 F 1111 15

5. Pointer Arithmetic

5.1. New address = old address + (integer * size of base type) &arr [2] = &arr [0] + (2 * 4) ==> for 32 bit &arr [2] = &arr [0] + (2 * 8) ==> for 64 bit

5.2. address + or - integer

5.3. integer + or - address

5.4. address - address

6. Pointers and Functions

6.1. Can use pointers as regular variable if declared in main if type *name = &variable already set void some_Func (type name) some_Func (name)

6.2. Pass by reference in the parameter void some_Func (type &name) some_Func (&name)

6.3. function can force reception of pointer of a parameter void some_Func (type *name)

7. Points and Arrays

7.1. a [n] is translated to statement *(a + n)

7.2. *p = arr [i] - gets the address of the element in arr [i]

7.3. *p = arr - same as int *p = arr [0]; *p = arr + 2 - same as int *p =arr [2];

7.4. *p++ - get the next element of the array - evaluated as if *(p++) due to right to left precedence

7.5. this is always true: &arr [2] < &arr[3] because this is same as: arr+2 < arr+3

8. Adding N to a pointer produces an element N elements away from point value