SlideShare a Scribd company logo
1 of 20
UNIT
III
POINTERS AND STRING
TOPICS: POINTER
• MEMORY ACCESS AND POINTERS
• POINTER BASICS
• DECLARING
• INITIALIZING
• DEREFERENCING A POINTER
• PARAMETER PASSING MECHANISM
• OPERATIONS ON POINTER
MEMORY
ACCESS
Memory access refers to
the ability to read from or
write to specific locations
in the computer's memory.
The memory in a computer
is organized into a
sequence of bytes, each
with a unique address.
MEMORY ACCESS
• Every variable is a memory
location and every memory
location has its address defined
which can be accessed through
ampersand (&) operator, which
denotes an address in memory
Address of a:
0x7ffd7218d764
Address of b:
0x7ffd7218d760
Address of c:
0x7ffd7218d75f
#include <stdio.h>
int main()
{
int a = 10;
double b = 20.5;
char c = 'A';
printf("Address of a: %pn", &a);
printf("Address of b: %pn", &b);
printf("Address of c: %pn", &c);
return 0;
}
Variables
• Variables in C are named storage locations that hold values of a
specific data type.
• When you declare a variable, the compiler allocates memory to
store its value, and you can access that memory using the
variable's name.
int age = 25;
// Declaring an integer variable 'age' and assigning it a value
Pointer
• Pointers are variables that store memory addresses. They allow
direct access to the memory location they point to.
• Pointers are declared with a specific data type, indicating the
type of data stored at the memory location.
• Example, int a=10;
• int *ptr; // Declaration of an integer pointer
10
10
a
Location
Value
Name of the variable
80F Address of the location
Pointer
• Value 10 can be accessed by using the variable name or the
address 80F
• Memory address are simply numbers can be assigned to some
other variable.
• The variable that holds the memory address is called pointer
variable
10
10
a
80F
10
80F
ptr
82C
Pointer name
Address of the
pointer
Address
of a
Pointer
• Value 10 can be accessed by using the variable name or the
address 80F
• Memory address are simply numbers can be assigned to some
other variable.
• The variable that holds the memory address is called pointer
variable
10
10
a
80F
10
80F
ptr
82C
Pointer name
Address of the
pointer
Address
of a
Address of operator
• The address-of operator (&) is used to get the memory address
of a variable.
int age = 25;
int *ptr = &age; // Assigning the address of 'age' to the pointer
'ptr'
Dereferencing operator
• The dereference operator (*) is used to access the value stored
at a memory address pointed to by a pointer.
int age = 25;
int *ptr = &age;
printf("Value at the memory address pointed by ptr: %dn", *ptr);
• Sample Program 1
• Pointer declaration and initialization
• Sample Program 2
• Pointer Basics
Void pointer
• Pointer that is not associated with any data type.
• It can point to objects of any type but doesn't provide
information about the type of data it points to.
• Void pointer sample Program
• Syntax:
• Void *pointer name;
Null pointer
• A null pointer in C is a pointer that does not point to any
memory location.
• It is a special constant value (often represented as 0 or NULL)
that is assigned to a pointer variable to indicate that it does not
currently point to a valid memory address.
• Null pointer sample program
• Syntax:
• Int *p=NULL;
Parameter
passing
Pass by value
Pass by reference
Pass by value
• The value of the argument is passed to the function.
• Changes made to the parameter inside the function do not
affect the original value.
• Sample Pgm
#include <stdio.h>
void incrementByValue(int x) {
x++;
printf("Inside function: x = %dn", x);
}
int main() {
int num = 5;
printf("Before function call: num = %dn", num);
incrementByValue(num);
printf("After function call: num = %dn", num);
return 0;
}
Pass by reference
• The address of the argument is passed to the function using a
pointer.
• Changes made to the parameter inside the function affect the
original value.
• Sample Pgm
#include <stdio.h>
void incrementByReference(int *x) {
(*x)++;
printf("Inside function: *x = %dn", *x);
}
int main() {
int num = 5;
printf("Before function call: num = %dn", num);
incrementByReference(&num);
printf("After function call: num = %dn", num);
return 0;
}

More Related Content

Similar to Pointers

Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
tech4us
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptx
Ananthi Palanisamy
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).ppt
georgejustymirobi1
 

Similar to Pointers (20)

Pointers
PointersPointers
Pointers
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Session 5
Session 5Session 5
Session 5
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
C
CC
C
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptx
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
 
Pointer
PointerPointer
Pointer
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
presentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).pptpresentation_pointers_1444076066_140676 (1).ppt
presentation_pointers_1444076066_140676 (1).ppt
 

Recently uploaded

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 

Pointers

  • 2. TOPICS: POINTER • MEMORY ACCESS AND POINTERS • POINTER BASICS • DECLARING • INITIALIZING • DEREFERENCING A POINTER • PARAMETER PASSING MECHANISM • OPERATIONS ON POINTER
  • 3. MEMORY ACCESS Memory access refers to the ability to read from or write to specific locations in the computer's memory. The memory in a computer is organized into a sequence of bytes, each with a unique address.
  • 4. MEMORY ACCESS • Every variable is a memory location and every memory location has its address defined which can be accessed through ampersand (&) operator, which denotes an address in memory
  • 5.
  • 6. Address of a: 0x7ffd7218d764 Address of b: 0x7ffd7218d760 Address of c: 0x7ffd7218d75f #include <stdio.h> int main() { int a = 10; double b = 20.5; char c = 'A'; printf("Address of a: %pn", &a); printf("Address of b: %pn", &b); printf("Address of c: %pn", &c); return 0; }
  • 7. Variables • Variables in C are named storage locations that hold values of a specific data type. • When you declare a variable, the compiler allocates memory to store its value, and you can access that memory using the variable's name. int age = 25; // Declaring an integer variable 'age' and assigning it a value
  • 8. Pointer • Pointers are variables that store memory addresses. They allow direct access to the memory location they point to. • Pointers are declared with a specific data type, indicating the type of data stored at the memory location. • Example, int a=10; • int *ptr; // Declaration of an integer pointer 10 10 a Location Value Name of the variable 80F Address of the location
  • 9. Pointer • Value 10 can be accessed by using the variable name or the address 80F • Memory address are simply numbers can be assigned to some other variable. • The variable that holds the memory address is called pointer variable 10 10 a 80F 10 80F ptr 82C Pointer name Address of the pointer Address of a
  • 10. Pointer • Value 10 can be accessed by using the variable name or the address 80F • Memory address are simply numbers can be assigned to some other variable. • The variable that holds the memory address is called pointer variable 10 10 a 80F 10 80F ptr 82C Pointer name Address of the pointer Address of a
  • 11. Address of operator • The address-of operator (&) is used to get the memory address of a variable. int age = 25; int *ptr = &age; // Assigning the address of 'age' to the pointer 'ptr'
  • 12. Dereferencing operator • The dereference operator (*) is used to access the value stored at a memory address pointed to by a pointer. int age = 25; int *ptr = &age; printf("Value at the memory address pointed by ptr: %dn", *ptr);
  • 13. • Sample Program 1 • Pointer declaration and initialization • Sample Program 2 • Pointer Basics
  • 14. Void pointer • Pointer that is not associated with any data type. • It can point to objects of any type but doesn't provide information about the type of data it points to. • Void pointer sample Program • Syntax: • Void *pointer name;
  • 15. Null pointer • A null pointer in C is a pointer that does not point to any memory location. • It is a special constant value (often represented as 0 or NULL) that is assigned to a pointer variable to indicate that it does not currently point to a valid memory address. • Null pointer sample program • Syntax: • Int *p=NULL;
  • 17. Pass by value • The value of the argument is passed to the function. • Changes made to the parameter inside the function do not affect the original value. • Sample Pgm
  • 18. #include <stdio.h> void incrementByValue(int x) { x++; printf("Inside function: x = %dn", x); } int main() { int num = 5; printf("Before function call: num = %dn", num); incrementByValue(num); printf("After function call: num = %dn", num); return 0; }
  • 19. Pass by reference • The address of the argument is passed to the function using a pointer. • Changes made to the parameter inside the function affect the original value. • Sample Pgm
  • 20. #include <stdio.h> void incrementByReference(int *x) { (*x)++; printf("Inside function: *x = %dn", *x); } int main() { int num = 5; printf("Before function call: num = %dn", num); incrementByReference(&num); printf("After function call: num = %dn", num); return 0; }