You are on page 1of 11

Pointer

In
C-Programming

Presented By:
Mahendra Singh Mahara
WHAT IS POINTER?
• pointeris a variable that stores the memory address of another
variable. It allows programmers to manipulate data directly in
memory, which can be more efficient and flexible than working
with variables directly.
WHY POINTER CAN BE USEFUL
1. MEMORY MANAGEMENT: pointers allow programmers to dynamically allocate and deallocate memory during
runtime. this is particularly useful when the program needs to use a variable-sized data structure like an array or a
linked list.
2. EFFICIENCY: pointers can improve the performance of a program because they allow direct access to the memory
location of a variable. this can be much faster than copying the value of a variable into a function, for example.
3. FUNCTION ARGUMENTS: c allows function arguments to be passed by reference, which is possible using
pointers. this means that a function can modify the value of a variable in the caller function without making a copy
of it.
4. DATA STRUCTURES: c does not have built-in data structures like linked lists, trees, or graphs. however, these data
structures can be implemented using pointers. this allows programmers to create custom data structures that fit the
specific needs of their program.
5. INTERACTING WITH HARDWARE: when programming hardware devices or working with low-level operations,
pointers are often used to interact with memory locations directly. this can be essential in embedded systems or
device drivers, where performance and direct memory access are critical.
DECLARATION OF POINTER

 To declare a pointer in C programming language, you use the “*” (asterisk) symbol before the pointer name. Here
is the syntax for declaring a pointer:
data_type *pointer_name;

 Where “Data_Type” is the data type of the variable that the pointer will point to, and “Pointer_Name” is the name
of the pointer variable.
int num = 10;
int *ptr = # // assigns the address of num to ptr
printf("%d", *ptr); // prints the value of num (which is 10)
HOW TO USE POINTER OPERATORS
• the "&" and "*" operators are used with pointers to get the address and value of a variable.
• The "&" operator is used to get the memory address of a variable. For example, if we have
an integer variable called num, we can get its memory address by using the "&" operator
like this:

int a = 10;
int *ptr = &a; // assigns the address of num to ptr
printf("%d", *ptr); // prints the value of num (which is 10)
PRINT DATA THROUGH POINTER
CHANGE DATA THROUGH POINTER
#include<stdio.h>
#include<conio.h>
int main()
{
int x = 5;
int *p;
p = &x;
*p = 10;
printf("%d\n", x);
return 0;
}
ARITHMETIC OPERATION THROUGH POINTER
#include<stdio.h>
#include<conio.h>
int main()
{
int a[5] = {1, 4, 8, 4, 9};
int *p;
p = a;
printf("%d\n", *(p + 1));
return 0;
}
CONCLUSION
• Pointers are a powerful tool for manipulating memory addresses in C
programming.
• With a solid understanding of pointers, you can write more efficient
and complex programs.
• Pointers provide direct access to memory.
• Pointers provide a way to return multiple values from a user defined
function without using return keyword.
• Pointers reduce the storage space and complexity of programs.
• Pointers reduce the execution time of programs.
• Pointers provide an alternate way to access individual array elements.
• Pointers allow us to perform dynamic memory allocation and
deallocation.
• Pointers allow us to create more complex data structures like linked
Any Questions…

THANK YOU

You might also like