L22-23 Pointer Basics
L22-23 Pointer Basics
- Compiler will allocate a memory location for Quantity and places the value in
that location. Suppose the address of that location is 5000, then
▪ During Execution of the program, the system always associates the name
quantity with the address 5000.
▪ We may have access to the value 50 by using either the name of the variable
quantity or the address 5000.
▪ Since memory addresses are simply numbers, they can be assigned to some
variables which can be stored in memory, like any other variable.
Commonly used in C than in many other languages (such as BASIC, Pascal, and
certainly Java, which has no pointers).
return 0;
}
5/7/2022 CSE 1051 Department of CSE 10
Declaring and initializing pointers
Example:
int *p; //declares a variable p as a pointer variable
that points to an integer data type.
The statement
#include <stdio.h>
int main(){
Now…
*p = 3; //assigns 3 to Quantity
5/7/2022 CSE 1051 Department of CSE 19
Summary
• Pointer concept
• Dereference operator *