Status: Tags: Links: C MOC
Pointers and References
Pointers
- Dereferencing
- useful when you only have the address in memory and you want to read or write the value in the address.
- 8 bytes
- Hold the location of variables
- Can change parameters of functions
- Used to modify variables sent to a function by getting adress as parameter
void foo(int* a)
as parameter, call usingfoo(&a)
*
plays 2 roles- When we declare a variable which is a pointer.
- When we want the value in the address. (Read or write)
Uses
- Allow us the modify parameters in a function
- Allows us to pass large objects to a function with a single pointer.
- Optimization: Avoids duplicating data
- Arrays are implemented using pointers in C
- So are strings
Syntax
&
to get adress of a value
*
access value at the adress
|
|
Questions
Backlinks
|
|
References:
Created:: 2021-09-13 14:35