filmov
tv
C Programming tutorial #15 Arrays and Pointers | Pointer arithmetic
![preview_player](https://i.ytimg.com/vi/IqOzieSXCNw/maxresdefault.jpg)
Показать описание
C Programming tutorial #15 Arrays and Pointers | Pointer arithmetic
This C Programming lecture covers the following topics:
00:10 Accessing arrays using pointers
03:46 C program to illustrate accessing arrays using pointers
07:58 Pre and post increment
09:21 sizeof Operator
11:30 pointer arithmetic
15:30 Comparing pointers
17:38 C Programming Example: Pointer subtraction in a string
ptr++ and ++ptr:
++ptr and ptr++ are both equivalent to ptr + 1
- though they are “incremented” at different times
Pointer Arithmetic:
Valid pointer operations:
- Assignment between pointers of the same type
- Addition/ subtraction between a pointer and an integer
- Comparison between two pointers that point to elements of the same array
- Subtraction between two pointers that point to elements of the same array
- Assignment or comparison with zero (NULL)
Pointer Arithmetic – Increment/Decrement:
Increment/decrement: if p is a pointer to type T, p++ increases the value of p by sizeof(T) (sizeof(T) is the amount of storage needed for an object of type T). Similarly, p-- decreases p by sizeof(T);
Add/Subtract Integers from Pointers:
Addition/subtraction with an integer: if p is a pointer to type T and n an integer, p+n increases the value of p by n*sizeof(T).
- Similarly, p-n decreases p by n*sizeof(T);
Comparing Pointers: Any pointer can be meaningfully compared for equality or inequality with zero.
This C Programming lecture covers the following topics:
00:10 Accessing arrays using pointers
03:46 C program to illustrate accessing arrays using pointers
07:58 Pre and post increment
09:21 sizeof Operator
11:30 pointer arithmetic
15:30 Comparing pointers
17:38 C Programming Example: Pointer subtraction in a string
ptr++ and ++ptr:
++ptr and ptr++ are both equivalent to ptr + 1
- though they are “incremented” at different times
Pointer Arithmetic:
Valid pointer operations:
- Assignment between pointers of the same type
- Addition/ subtraction between a pointer and an integer
- Comparison between two pointers that point to elements of the same array
- Subtraction between two pointers that point to elements of the same array
- Assignment or comparison with zero (NULL)
Pointer Arithmetic – Increment/Decrement:
Increment/decrement: if p is a pointer to type T, p++ increases the value of p by sizeof(T) (sizeof(T) is the amount of storage needed for an object of type T). Similarly, p-- decreases p by sizeof(T);
Add/Subtract Integers from Pointers:
Addition/subtraction with an integer: if p is a pointer to type T and n an integer, p+n increases the value of p by n*sizeof(T).
- Similarly, p-n decreases p by n*sizeof(T);
Comparing Pointers: Any pointer can be meaningfully compared for equality or inequality with zero.