POINTERS
◤
POINTERS
◤
Address of a memory location
◤
What is a Pointer
◤
What is a Pointer
◤
What is a Pointer
◤
Pointer Operators in C�
◤
Pointer Operators in C�
◤
◤
◤
Declaring a Pointer in C�
◤
Declaring a Pointer in C�
◤
Assigning Value to a Pointer Variable�
◤
◤
Derefrencing Pointer in C�
◤
Derefrencing Pointer in C�
◤
Derefrencing Pointer in C�
◤
a) To declare a pointer to a variable:
◤
b)Initialization of pointer variables:
◤
Benefits of using pointers are:-
◤
C Pointer Arithmetic�
The pointer arithmetic refers to the arithmetic operations that can be performed on a pointer. It is slightly different from the ones that we generally use for mathematical calculations as only a limited set of operations can be performed on pointers.
◤
C Pointer Arithmetic
These operations include:
◤
Incrementing a Pointer:�
◤
Incrementing a Pointer:�
◤
Decrementing a Pointer:�
◤
Decrementing a Pointer:�
◤
Adding an Integer to a Pointer:�
to the pointer's address.
◤
Subtracting an Integer from a Pointer:
from the pointer's address.
◤
Subtracting Two Pointers:�
◤
Dynamic memory allocation
◤
Dynamic memory allocation
◤
C Dynamic Memory Allocation�
◤
�
To allocate memory dynamically, library functions are
◤
malloc() (Memory Allocation):
◤
Malloc syntax
◤
Malloc syntax
Ptr= |
GAR.VALUE | GV | GV | GV | GV |
----10 bytes of memory allocated------ |
◤
calloc() (Contiguous Allocation):
◤
Calloc Syntax: �
◤
Calloc Syntax: �
Syntax:
| 0 | 1 | 2 | 3 | 4 |
Ptr= | 0 | 0 | 0 | 0 | 0 |
| ------------------10 byte of memory allocated-------------- | ||||
◤
realloc() (Reallocation):
◤
Realloc Syntax: �
◤
Realloc Syntax: �
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Ptr= | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| ----------------20 bytes memory allocated ----------------- | |||||||||
◤
free():
◤
free()Syntax:
◤
Structures
◤
Key characteristics of structures:
◤
Key characteristics of structures:
◤
How to Create Structures in C?�
◤
The basic syntax for a C structure is:�
◤
The basic syntax for a C structure is:�
◤
Structure Example
◤
How to Create Structure Variables?�
◤
There are 2 ways to create a variable to access data members in a structure�
◤
2. Outside the main function:�
◤
How to access Data Members in Structures in C�
◤
How to access Data Members in Structures in C�
◤