Download presentation
Presentation is loading. Please wait.
Published byΕυμελια Σπανός Modified over 5 years ago
1
C Programming Lecture-8 Pointers and Memory Management
$p!derLabWeb C Programming Lecture-8 Pointers and Memory Management
2
What are pointers? Pointers are the special kind of variables which can store the addresses of other variables.
3
How to declare a pointer?
To declare a pointer we use “ * ” symbol. Syntax :- type_name *var_name; Eg. int *a; // pointer to an integer. double *b; // pointer to a double. float *c; // pointer to a float. char *d; // pointer to a character.
4
Null Pointers Null pointer is the pointer which is pointing to null. Eg. int *a = NULL; double *b = NULL;
5
How pointers are used? We know pointers are used to store the address of other variables then we have to use the & symbol to get the address of other variable. Suppose a int variable is declared Now declaring the pointer b pointing to a. int *b = &a;
6
Dynamically Allocating Memory
For dynamically allocating memory to a pointer we use malloc function. Prototype :- void *malloc( int size ); Eg:- int *a = (*int) malloc(4 * sizeof(int));
7
Resizing and Releasing Memory
For resizing the size of the pointer we have realloc function. Prototype :- void *realloc(void *ptr, int newsize); And for releasing the memory we have free function. void free (void *address);
8
Thank you!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.