filmov
tv
C Programming tutorial #14 Null Pointer, Typecasting, Pointer Arithmetic

Показать описание
C Programming tutorial #14 pointer variable, Dereferencing operator, Null pointer, Pointer types, Typecasting, Pointers and arrays, Pointer arithmetic.
00:20 Contents of a pointer variable
01:46 Dereferencing operator, Null pointer
05:20 Pointer types, Typecasting and Examples
10:40 Pointers and arrays, Pointer arithmetic
- The "dereferencing operator" is the asterisk and it is used as follows:
*p= 7;
- will copy 7 to the address pointed to by p. Thus if p "points to" k, the above statement will set the value of k to 7.
- Using '*' is a way of referring to the value of that which p is pointing to, not the value of the pointer itself.
NULL pointers:
- Values of a pointer variable:
- Usually the value of a pointer variable is a pointer to some other variable
- A null pointer is a special pointer value that is known not to point anywhere.
- No other valid pointer, to any other variable, will ever compare equal to a null pointer !
- Predefined constant NULL, defined in stdio.h
- Good practice: test for a null pointer before inspecting the value pointed !
Pointer types:
- C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
- A void pointer is a generic pointer. For example, a pointer to any type can be compared to a void pointer
- Typecasts can be used to convert from one type of pointer to another under the proper circumstances
Pointers and arrays:
- In C, there is a strong relationship between pointers and arrays
- Any operation that can be achieved by array subscripting can also be done with pointers
00:20 Contents of a pointer variable
01:46 Dereferencing operator, Null pointer
05:20 Pointer types, Typecasting and Examples
10:40 Pointers and arrays, Pointer arithmetic
- The "dereferencing operator" is the asterisk and it is used as follows:
*p= 7;
- will copy 7 to the address pointed to by p. Thus if p "points to" k, the above statement will set the value of k to 7.
- Using '*' is a way of referring to the value of that which p is pointing to, not the value of the pointer itself.
NULL pointers:
- Values of a pointer variable:
- Usually the value of a pointer variable is a pointer to some other variable
- A null pointer is a special pointer value that is known not to point anywhere.
- No other valid pointer, to any other variable, will ever compare equal to a null pointer !
- Predefined constant NULL, defined in stdio.h
- Good practice: test for a null pointer before inspecting the value pointed !
Pointer types:
- C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
- A void pointer is a generic pointer. For example, a pointer to any type can be compared to a void pointer
- Typecasts can be used to convert from one type of pointer to another under the proper circumstances
Pointers and arrays:
- In C, there is a strong relationship between pointers and arrays
- Any operation that can be achieved by array subscripting can also be done with pointers