0% found this document useful (0 votes)
13 views14 pages

Outstanding

The document is a presentation on pointers in C programming, covering their definition, operations, and advantages. It includes topics such as pointer declaration, initialization, memory addresses, pointer arithmetic, and their use with arrays, functions, and structures. The presentation emphasizes the efficiency and flexibility that pointers provide in programming.

Uploaded by

satguruitcell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views14 pages

Outstanding

The document is a presentation on pointers in C programming, covering their definition, operations, and advantages. It includes topics such as pointer declaration, initialization, memory addresses, pointer arithmetic, and their use with arrays, functions, and structures. The presentation emphasizes the efficiency and flexibility that pointers provide in programming.

Uploaded by

satguruitcell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Presentation

GURU KASHI UNIVERSITY


Talwandi sabo(Bathinda)

SUBMITTED BY :- Aditya kumar (123309180001) SUBMITTED TO:-


Er. Harmandeep kaur
Md Meraj Ansari (123309180021)

Manu Ram (123309180048)

Anshu kumar (123309180007)

Wahaj Alam (1233309180047)


Contents:-
• Introduction to Pointers in C
• Rules of pointer Operation

• Declaring and Initializing Pointers

• Understanding Memory Addresses

• Pointer Arithmetic

• Pointers and Arrays

• Pointers and Functions

• Pointers and Structures

• Advantages of pointer
Introduction to
Pointers in C
• A Pointer is a variable which contain the address of
another variable in memory.

• Pointers are used in C program to access the memory


and manuplate the address.

• Pointer syntax:
data_type*var_name;
• Examples :
• int *p; char*p;
EXAMPLE PROGRAM
#include <stdio.h>
int main()
{
int *ptr, q; //declaration
q = 50;
ptr = &q; //initialization
printf("%d", *ptr); //display q's value using ptr variable
printf("%d", *ptr);
return 0;
}

output: 50
RULES OF POINTER OPERATIONS

• A pointer variable can be assigned the address of another variable.

• A pointer variable can be assigned the values of another pointer variable.

• A pointer variable can be initialized with NULL or zero value.

• A pointer variable can be pre-fixed or post-fixed with increment or decrement


operators.

• An integer value may be added or subtracted from a pointer variable.


Advantages
• A pointer enables us to access a variable that is defined outside the function.

• Pointers are more efficient in handling the data tables.

• Pointers reduce the length and complexity of a program.

• They increase the execution speed.

• The use of a pointer array to character strings results in saving of data storage
space in memory.
Declaring and Initializing
Pointers
1 Pointer Declaration
Pointers are declared using the * operator, specifying the data type
they point to. For example, int* myPtr;

2 Pointer Initialization
Pointers can be initialized to point to a specific memory address or
the value NULL to indicate no valid address.

3 Address-of Operator
The & operator retrieves the memory address of a variable, which
can then be assigned to a pointer.
Understanding Memory Addresses
Memory Locations Indirection Efficiency

Every piece of data in a C Pointers use the Pointers can improve


program is stored at a indirection operator (*) to performance by allowing
unique memory address. access the value stored at direct memory access,
Pointers give you access a memory address, rather avoiding the overhead of
to these addresses, letting than the address itself. copying data between
you interact with and This makes them a variables.
modify the data directly. versatile tool for working
with data.
Pointer Arithmetic
1 Incrementing Pointers 2 Dereferencing Pointers
Adding an integer to a pointer The * operator is used to access
moves the pointer to the next the value stored at a pointer's
memory location, based on the memory address.
size of the data type.

3 Pointer Comparisons
Pointers can be compared to see if they point to the same or different
memory locations.
Pointers and Arrays
Array Decay Pointer Arithmetic
When an array is passed to a Pointers can be used to traverse
function, it "decays" into a pointer and access elements in an array,
to the first element of the array. using pointer arithmetic to move
between elements.

Dynamic Allocation
Pointers are crucial for dynamically allocating memory for arrays, allowing for
flexible and efficient data storage.
Pointers and Functions

Call by Value Call by Reference Return Pointers


When a variable is Passing a pointer to a Functions can also return
passed to a function, a function allows the pointers, allowing them
copy of the value is used, function to directly to pass back complex
leaving the original modify the original data structures or
unchanged. variable, known as "call dynamically allocated
by reference". memory.
Pointers and Structures
Direct Access Pointers can be used to directly access
and modify the members of a structure.

Dynamic Allocation Dynamically allocated structures can be


accessed and manipulated using
pointers.
Flexibility Pointers provide a flexible way to work
with complex data structures, simplifying
code and improving performance.
THANK YOU

You might also like