C Pointers and Memory Management

C Pointers and Memory Management
Slide Note
Embed
Share

Pointers in C are powerful features that allow you to work with memory addresses, facilitating dynamic memory allocation and manipulation of variables. Learn how pointers differentiate C from other languages like Java and Python, and explore the difference between normal variables and pointer variables. Dive deeper into examples showcasing the use of pointers to access and manipulate variable values.

  • C programming
  • Pointers
  • Memory management
  • Variable manipulation
  • Dynamic memory allocation

Uploaded on Mar 03, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. C Pointers

  2. Pointers Pointers in C language is a variable that stores/points the address of another variable. We can have a pointer to any variable type. Such as int, float, char, double, short etc.

  3. Pointers How to find address of variable Pointers are powerful features of C and (C++) programming that differentiates it from other popular programming languages like: Java and Python.

  4. Pointers Use of pointers? A Pointer in C is used to allocate memory dynamically i.e. at run time. Syntax of pointers data_type* var_name; Example : int *p; char *p; Where, * is used to denote that p is pointer variable and not a normal variable.

  5. Difference between normal variable and pointer variable Normal variable stores the value whereas pointer variable stores the address of the variable. Always C pointer is initialized to null, i.e. int *p = null. The value of null pointer is 0. & symbol is used to get the address of the variable. * symbol is used to get the value of the variable that the pointer is pointing to.

  6. Example:

  7. Other Example with explanation int x=1, y=2; int *ip;

  8. Other Example with explanation int x=1, y=2; int *ip;

  9. Other Example with explanation int x=1, y=2; int *ip; ip= &x;

  10. Other Example with explanation Pointer, Variables and Memory Now the assignments x = 1 and y = 2obviously load these values into the variables. int x=1, y=2; int *ip; ip is declared to be a pointer to an integer and is assigned to the address of x (&x). ip= &x; So ip gets loaded with the value 100.

  11. Other Example with explanation int x=1, y=2; int *ip; ip= &x; y= *ip

  12. Other Example with explanation y gets assigned to the contents of ip. int x=1, y=2; int *ip; ip= &x; In currently memory location 100 (the location of x). this example points ip to So y gets assigned to the values of x -- which is 1. ip= &x; y= *ip

  13. Other Example with explanation int x=1, y=2; int *ip; ip= &x; x=ip

  14. Other Example with explanation int x=1, y=2; int *ip; ip= &x;

  15. Other Example with explanation int x=1, y=2; int *ip; ip= &x; *ip=3

  16. Other Example with explanation int x=1, y=2; int *ip; ip= &x;

  17. Assignment: Write sample C program using pointer concept and find following parameters. 1. Size of pointer 2. Display address of variable using pointer and without pointer 3. Add Two numbers using pointers concept and store the resultant value in first variable using pointer concept only. 4. Display the value of variable using pointer concept without using pointer variable (hint: *(&Var))

More Related Content