C TutorialLesson 22Free preview
C Pointers
This lesson is part of C · All levels
Summary
A pointer is a special variable that stores memory addresses belonging to other variables, thus allowing indirect access to data. Pointers are declared with a * followed by the designated data type, e.g. int *p, and then filled in with values using & on the destination variable. Through a pointer, a function can change the value of the source variable and a program can manage the dynamic data structure. Pointer error such as accessing a blank address is the most common source of bugs in C.
Key points
- The int *p declaration means that p is a pointer to the int-type data.
- P = &var puts the address var to p, whereas *p takes its value
- Pointers that have not been initialized should not be deferred
- Pointer allows the function to change the original data by passing by reference
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.