SlideShare a Scribd company logo
1 of 16
Pointers in C
Introduction:
• Pointers are a fundamental concept in the C programming language.
• They provide a way to manipulate memory addresses and access data
indirectly.
• Understanding pointers is crucial for efficient memory management
and working with complex data structures in C
What is a Pointer?
• A pointer is a variable that stores the memory address of another
variable.
• It allows us to indirectly access and modify the value stored at a
specific memory location.
Declaring Pointers:
Pointers are declared using the asterisk (*) symbol.
Syntax: data_type *pointer_name;
Example: int *ptr;
Initializing Pointers:
• Pointers can be initialized with the address of another variable.
• Example: int *ptr = #
What is a Pointer?
Initializing Pointers:
#include <stdio.h>
int main() {
int num; // Declare an integer variable
int *ptr; // Declare a pointer variable
num = 10; // Initialize the value of num
ptr = &num; // Assign the address of num to ptr
int value = *ptr; // Access the value stored in num indirectly through the pointer
printf("Value of num: %dn", num);
printf("Value accessed through the pointer: %dn", value);
return 0;
}
Introduction to Structures in C
• Structures are user-defined data types in C.
• They allow you to group variables of different types under a single
name.
• Structures provide a convenient way to represent related data.
Syntax:
• The syntax for defining a structure in C is as follows:
• struct structure_name
{ data_type member1;
data_type member2; ... };
Declaring Structure Variables:
• After defining a structure, you can declare variables of that structure
type.
• Syntax: struct structure_name variable_name
Accessing Structure Members:
• Structure members can be accessed using the dot (.) operator.
• Syntax: variable_name.member_name
Example
struct Person {
char name[50];
int age;
char address[100];
};
int main() {
struct Person person1 = {"John Doe", 25, "123 Main Street"}; // Declare and initialize a structure variable
// Access and print structure members
printf("Name: %sn", person1.name);
printf("Age: %dn", person1.age);
printf("Address: %sn", person1.address);
return 0;
}
Pointers to Structures in C
• Pointers in C are variables that store memory addresses.
• Pointers to structures allow you to access and manipulate structure
data indirectly.
• They provide an efficient way to work with complex data structures.
Syntax:
• The syntax for declaring a pointer to a structure is as follows:
• struct structure_name *pointer_name;
Accessing Structure Members using Pointers:
• Accessing Structure Members using Pointers:
• Pointers to structures are used to access structure members using the
arrow (->) operator.
• Syntax: pointer_name->member_name;
struct Person {
char name[50];
int age;
char address[100];
};
int main() {
struct Person person1;
struct Person *ptr; // Declare a pointer to a structure
ptr = &person1; // Assign the address of person1 to the pointer
// Access and modify structure members using the pointer
ptr->age = 25;
// Access and modify structure members using the pointer
ptr->age = 25;
strcpy(person1.name, "John Doe");
person1.age = 25;
strcpy(person1.address, "123 Main Street");
// Access and print structure members using the pointer
printf("Name: %sn", ptr->name);
printf("Age: %dn", ptr->age);
printf("Address: %sn", ptr->address);
return 0;
}

More Related Content

Similar to Pointers and Structures.pptx

Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referentialbabuk110
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptxKorbanMaheshwari
 
Pointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxPointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxahmedbadr608094
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationRabin BK
 
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.pptxAnanthi Palanisamy
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)Mohd Effandi
 
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.pptxsangeeta borde
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxGebruGetachew2
 
Presentation of c 1
Presentation of c 1Presentation of c 1
Presentation of c 1Love preet
 

Similar to Pointers and Structures.pptx (20)

Structures in C
Structures in CStructures in C
Structures in C
 
Data Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self ReferentialData Structure & Algorithm - Self Referential
Data Structure & Algorithm - Self Referential
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
 
Pointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptxPointers_in_c_2024.01.10_embedded _c.pptx
Pointers_in_c_2024.01.10_embedded _c.pptx
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
pointers (1).ppt
pointers (1).pptpointers (1).ppt
pointers (1).ppt
 
C Programming Unit-4
C Programming Unit-4C Programming Unit-4
C Programming Unit-4
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
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
 
Chp3(pointers ref)
Chp3(pointers ref)Chp3(pointers ref)
Chp3(pointers ref)
 
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
 
Structure
StructureStructure
Structure
 
structure1.pdf
structure1.pdfstructure1.pdf
structure1.pdf
 
4 Pointers.pptx
4 Pointers.pptx4 Pointers.pptx
4 Pointers.pptx
 
CHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptxCHAPTER -4-class and structure.pptx
CHAPTER -4-class and structure.pptx
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
 
Structures
StructuresStructures
Structures
 
Presentation of c 1
Presentation of c 1Presentation of c 1
Presentation of c 1
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 

Recently uploaded

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Pointers and Structures.pptx

  • 2. Introduction: • Pointers are a fundamental concept in the C programming language. • They provide a way to manipulate memory addresses and access data indirectly. • Understanding pointers is crucial for efficient memory management and working with complex data structures in C
  • 3. What is a Pointer? • A pointer is a variable that stores the memory address of another variable. • It allows us to indirectly access and modify the value stored at a specific memory location.
  • 4. Declaring Pointers: Pointers are declared using the asterisk (*) symbol. Syntax: data_type *pointer_name; Example: int *ptr;
  • 5. Initializing Pointers: • Pointers can be initialized with the address of another variable. • Example: int *ptr = #
  • 6. What is a Pointer?
  • 7. Initializing Pointers: #include <stdio.h> int main() { int num; // Declare an integer variable int *ptr; // Declare a pointer variable num = 10; // Initialize the value of num ptr = &num; // Assign the address of num to ptr int value = *ptr; // Access the value stored in num indirectly through the pointer printf("Value of num: %dn", num); printf("Value accessed through the pointer: %dn", value); return 0; }
  • 8. Introduction to Structures in C • Structures are user-defined data types in C. • They allow you to group variables of different types under a single name. • Structures provide a convenient way to represent related data.
  • 9. Syntax: • The syntax for defining a structure in C is as follows: • struct structure_name { data_type member1; data_type member2; ... };
  • 10. Declaring Structure Variables: • After defining a structure, you can declare variables of that structure type. • Syntax: struct structure_name variable_name
  • 11. Accessing Structure Members: • Structure members can be accessed using the dot (.) operator. • Syntax: variable_name.member_name
  • 12. Example struct Person { char name[50]; int age; char address[100]; }; int main() { struct Person person1 = {"John Doe", 25, "123 Main Street"}; // Declare and initialize a structure variable // Access and print structure members printf("Name: %sn", person1.name); printf("Age: %dn", person1.age); printf("Address: %sn", person1.address); return 0; }
  • 13. Pointers to Structures in C • Pointers in C are variables that store memory addresses. • Pointers to structures allow you to access and manipulate structure data indirectly. • They provide an efficient way to work with complex data structures.
  • 14. Syntax: • The syntax for declaring a pointer to a structure is as follows: • struct structure_name *pointer_name;
  • 15. Accessing Structure Members using Pointers: • Accessing Structure Members using Pointers: • Pointers to structures are used to access structure members using the arrow (->) operator. • Syntax: pointer_name->member_name;
  • 16. struct Person { char name[50]; int age; char address[100]; }; int main() { struct Person person1; struct Person *ptr; // Declare a pointer to a structure ptr = &person1; // Assign the address of person1 to the pointer // Access and modify structure members using the pointer ptr->age = 25; // Access and modify structure members using the pointer ptr->age = 25; strcpy(person1.name, "John Doe"); person1.age = 25; strcpy(person1.address, "123 Main Street"); // Access and print structure members using the pointer printf("Name: %sn", ptr->name); printf("Age: %dn", ptr->age); printf("Address: %sn", ptr->address); return 0; }