UNIT 2 C Prog
UNIT 2 C Prog
What is a Pointer?
A pointer is a special variable that stores the memory address of another variable.
Declara on of Pointer
Syntax:
data_type *pointer_name;
Example:
Once a pointer is declared, you can assign the address of a variable to it using the & (address of)
operator.
Example:
int x = 10;
int *p;
Now, p points to x.
The indirec on operator * is used to access the value stored at the memory loca on a pointer is
poin ng to.
Example:
int x = 20;
int *p = &x;
prin ("%d", *p); // Output: 20
The address-of operator & is used to get the memory address of a variable.
Example:
int x = 15;
5. Pointer Arithme c
Example:
int *p = arr;
Dynamic memory alloca on allows you to allocate memory at run me using pointers.
In C:
int *p;
*p = 50;
Example:
int *p = arr;
*p = *p + 5;
int main() {
int x = 10;
update(&x);