Unit 7Pointers
Follows IGNOU MCS-201, Unit 7
Every variable lives at some address in memory. A pointer is a variable that stores such an address, which lets a program reach and change data indirectly. Pointers are how C functions modify their caller’s variables, how arrays and strings are really handled, and how memory is requested while a program runs. This unit builds the idea step by step, from addresses to dynamic memory allocation.
In this unit you will learn to
- Explain what an address and a pointer are, and use the
&and*operators. - Declare, initialise and assign pointers, including pointers to pointers, null pointers and
voidpointers. - Perform pointer arithmetic and know which operations are allowed.
- Pass pointers to functions to change the caller’s variables and to return several results.
- Relate array subscripts to pointer expressions, for one- and two-dimensional arrays.
- Use arrays of pointers and allocate memory at run time with
mallocandfree. - Handle strings through character pointers and arrays of pointers to strings.
Sections in this unit
- 7.1Addresses, Pointers and the & and * OperatorsUnderstand memory addresses, what a pointer is, and how the address-of operator & and the indirection operator * work.10 min
- 7.2Declaring and Assigning PointersDeclare and initialise pointers, change variables through them, and use pointers to pointers, null pointers and void pointers safely.12 min
- 7.3Pointer ArithmeticAdd and subtract integers from pointers, subtract and compare pointers, and learn which pointer operations are not allowed.7 min
- 7.4Passing Pointers to FunctionsPass addresses to functions to change the caller's variables, return several results through pointer parameters, and avoid returning dangling pointers.14 min
- 7.5Arrays and PointersSee how array names convert to pointers, write subscripts as pointer expressions, and access two-dimensional arrays with pointer notation.12 min
- 7.6Arrays of Pointers and Dynamic Memory AllocationDeclare arrays of pointers, allocate and release memory at run time with malloc and free, and build a table whose size is chosen at run time.10 min
- 7.7Pointers and StringsHandle strings through character pointers, understand string literals, and store and sort several strings with an array of pointers.13 min