SlideShare a Scribd company logo
Presentation. Programming
Submitted by
Saad Lodhi
Nabiha Rana
Dua Safdar
Muqaddas Hanif
Submitted to Mam Faiza
Pointer
A pointer is a variable in programming
languages, particularly C and C++, that stores
the memory address of another variable.
Pointers are a powerful feature of these
languages because they provide direct
access to memory and allow for efficient
manipulation of data structures and dynamic
memory allocation.
Functions of pointer
1. Direct Memory Access: Pointers enable direct
manipulation of memory, which can improve
performance for certain operations by
eliminating the need to copy data
1. Dynamic Memory Allocation: Pointers
are essential for allocating memory
dynamically using functions like
malloc and free in C, and new and
delete in C++.
Functions of pointer
Data Structures: Pointers are used to
implement complex data structures
such as linked lists, trees, and graphs.
3Function Arguments: Pointers can be
used to pass large amounts of data to
functions efficiently by passing the
address of the data rather than the data
itself.
3
Functions of pointer
Array Management: Pointers provide efficient
ways to iterate through arrays and manipulate
array elements.
Pointer Arithmetic: Allows for navigation
through memory blocks, which is useful
for various algorithms and operations.
Types of pointer
Null Pointer: A pointer that is initialized
to NULL or 0. It does not point to any
valid memory location.int *ptr = NULL;
Void Pointer (Generic
Pointer): A special type of
pointer that can point to any
data type. It is often used
for generic functions.void
*ptr;
Dangling Pointer: A pointer that points
to a memory location that has been
freed or deallocated. Using a dangling
pointer can lead to undefined
behavior.int *ptr = (int
*)malloc(sizeof(int));
free(ptr); // ptr is now a dangling pointer
Wild Pointer: An uninitialized pointer
that can contain any arbitrary address.
Using wild pointers can result in
unpredictable behavior.int *ptr; // ptr is a
wild pointer
1
2
3
4
Usage and deceleration
Pointer Declarationint *ptr; // Declares a
pointer to an integer
char *ptr; // Declares a pointer to a
character
• Pointer Initializationint x = 10;
• int *ptr = &x; // ptr now holds the
address of x
• Dereferencing a PointerDereferencing a
pointer means accessing the value stored
at the memory address the pointer is
pointing to.int x = 10;
• int *ptr = &x;
• printf(“%d”, *ptr); // Outputs 10
Pointer ArithmeticPointer arithmetic
involves operations like addition and
subtraction on pointers, typically used for
iterating through arrays.int arr[] = {10, 20,
30, 40, 50};
int *ptr = arr;
printf(“%d”, *(ptr + 2)); // Outputs 30
Conclusion
Pointers are a fundamental aspect of C and C++
programming, providing powerful capabilities for
memory management, data structure manipulation, and
efficient function calling. However, they require careful
handling due to the potential for errors and undefined
behavior. Understanding pointers and their various
types and functions is essential for mastering low-level
programming and system design.
Reference
Reference is a value that enables a program
to indirectly access a particular piece of data
stored in memory. Rather than containing
the actual data itself, a reference contains
information about the location of the data,
which can be an object, variable, array, or
function.
Characteristics of reference
• Indirect Access: References allow
access to data indirectly by storing the
memory address where the data is
located.
Characteristics of reference
• Abstraction: References abstract away the direct
manipulation of memory addresses, making code
safer and easier to read.
• Immutable Binding: In many languages, once
a reference is set to point to a particular data
object, it cannot be changed to point to a
different object.
Reference types of programming language
Java:In Java, all non-primitive types (objects,
arrays) are reference types.String str = “Hello”;
int[] numbers = {1, 2, 3};
• C#:C# uses reference types for classes,
arrays, delegates, and more.Person person
= new Person();
• int[] numbers = {1, 2, 3};
C++:C++ supports both references and
pointers, but references are generally safer and
used for parameter passing and return
values.int x = 10;
int &ref = x; // ref is a reference to x
Example of reference usage
Example of Reference UsageJava Examplepublic class ReferenceExample {
public static void main(String[] args) {
Person person1 = new Person(“Alice”);
Person person2 = person1; // person2 is a reference to the same Person object as person1
person2.setName(“Bob”);
System.out.println(person1.getName()); // Outputs “Bob”
}
}
class Person {
private String name;
public Person(String name) {
Continue….. ..
This.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
In this example:person1 and person2 both
reference the same Person object.Changing the
name via person2 also reflects when accessing the
name via person1, demonstrating shared access to
the object.
Conclusion
ConclusionReferences are a
fundamental concept in programming
that enable efficient, indirect access to
data. They are widely used in object-
oriented programming, parameter
passing, and the implementation of
dynamic data structures.
Understanding how references work
and how to use them effectively is
crucial for developing robust and
efficient software.
Memory allocation
Definition
Memory allocation in programming refers
to the process of reserving a portion of
computer memory for the storage of data
during the execution of a program.
Types of memory allocation
1 SMA
2DMA
Static memory allocation
Definition
• Static memory allocation is a method of
allocating memory at compile time before
the associated program is executed. The
memory allocated using static memory
allocation is fixed and cannot be changed
during the runtime of the program. This
type of allocation is typically used for
global variables, static variables, and
constants.
Advantages of static memory allocation
• Predictability:Since memory is allocated
at compile time, the program’s memory
requirements are known beforehand,
making it easier to manage resources.
• No Fragmentation:Static memory allocation
does not suffer from fragmentation issues,
which are common in dynamic memory
allocation.
• Runtime Efficiency:There is no need
for runtime memory allocation and
deallocation, reducing the overhead
and potential runtime errors.
• Simplicity:Static allocation is simpler to
implement and understand, reducing the
complexity of memory management.
Characteristics of static memory
Compile-Time Allocation:Memory is
allocated during the compilation of the
program.The size and type of memory
allocation are known beforehand, making
it predictable.
• Fixed Size:The size of the allocated memory
block is fixed and cannot be altered at
runtime.This means the programmer must
know the required memory size in advance.
• Efficiency:Because the memory is allocated at
compile time, there is no runtime overhead for
memory allocation and deallocation.This can lead
to more efficient memory usage for certain types
of applications.
Example
• Example of Static Memory AllocationGlobal
VariablesIn C and C++, global variables are
allocated statically.#include <stdio.h>
•
• int globalVar = 10; // Statically allocated global
variable
•
• void display() {
• printf(“Global Variable: %dn”, globalVar);
• }
•
• int main() {
• display();
• return 0;
• }
Conclusion
• ConclusionStatic memory allocation is a
fundamental concept in programming where
memory is allocated at compile time. It offers
predictability, efficiency, and simplicity, making it
suitable for scenarios where memory requirements
are well-defined and constant. However, its lack of
flexibility and potential for memory waste limit its
applicability in dynamic and complex applications.
Understanding static memory allocation is crucial
for efficient resource management and optimal
program performance in various programming
contexts.
Dynamic memory allocation
Definition
Dynamic memory allocation is a
type of memory allocation which
provides memory during the
time of allocation
Dynamic memory allocation refers to the process of
allocating memory at runtime as opposed to compile time.
This allows programs to request memory as needed and
release it when it is no longer required, enabling efficient
use of memory for varying data sizes and structures.
Dynamic memory allocation is crucial for implementing
flexible data structures like linked lists, trees, and more.
Types of dynamic memory allocation
There are four types of dynamic memory allocation
Malloc Function
Header file for DMA
(Stdlib. h)
Definition:
Melloc function create a single block of give size .
During the time of allocation .
Syntax:
Pre= {data type} malloc (size of)
Example:
Ptr= (intr*) malloc (n*size of(intr)}
Calloc…. …
Definition
• Create bunch of blocks of given size during the time
of allocation
Syntax:
• Ptr= (data type*)collac(sizeof)
Example:
Ptr= (intr*) calloc (n, sizeof{intr})
Realloc… …
Definition:
• Realloc function recreates already
created blocks of given size.
Syntax:
• Ptr: (data type) realloc (old ptr new sizeof)
Example:
Ptr(data type*) realloc (ptr,n*sizeof(intr)}
Free()… …
Definition
Free () function deletes the allocated memory .
• During the time of allocation.
Syntax
Free (pointer)
Example:
Free(ptr)
The End …. …

More Related Content

PPT
cs8251 unit 1 ppt
praveenaprakasam
 
PPTX
C Pointers.pptx
NiteshSahni8
 
PPTX
object oriented programming part inheritance.pptx
urvashipundir04
 
PDF
C Interview Questions and Answers by Scholarhat
Scholarhat
 
PPTX
Technical Interview
prashant patel
 
PDF
C++ Programming with examples for B.Tech
ashutoshgupta1102
 
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
PDF
C Interview Questions PDF By Scholarhat.pdf
Scholarhat
 
cs8251 unit 1 ppt
praveenaprakasam
 
C Pointers.pptx
NiteshSahni8
 
object oriented programming part inheritance.pptx
urvashipundir04
 
C Interview Questions and Answers by Scholarhat
Scholarhat
 
Technical Interview
prashant patel
 
C++ Programming with examples for B.Tech
ashutoshgupta1102
 
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
ApurvaLaddha
 
C Interview Questions PDF By Scholarhat.pdf
Scholarhat
 

Similar to programming presentation group 7 ppt..pdf (20)

PPTX
Unit 1
donny101
 
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
babasahebgaikwad8
 
PPTX
Introduction-to-C-Programming (1ggggggggggggggggg).pptx
middollaganeshreddy0
 
PDF
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Ovidiu Farauanu
 
PPTX
TAPASH kumar das its my college pptasjhk
destroyer7992
 
PPTX
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Selvaraj Seerangan
 
PPTX
C programming basic concepts of mahi.pptx
KorbanMaheshwari
 
PDF
OOP UNIT 1_removed ppt explaining object.pdf
rajbaibhav004
 
PPTX
Lecture 3.mte 407
rumanatasnim415
 
PPTX
DSD Unit 1 Abstract Data Type data structures design notes.pptx
yuvaraniit
 
PPTX
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
PPTX
Basic Concepts of C Language.pptx
KorbanMaheshwari
 
PDF
Frequently asked tcs technical interview questions and answers
nishajj
 
PPTX
Introduction-to-Python-for-better-knowledge-
singh08ravinder
 
PPTX
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
ssuser5610081
 
PPTX
Unit-5.1.pptx programing in c language lesson 5
BhumiMakkar
 
PPTX
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
PPTX
venkatesh.pptx
KishoreRedla
 
PDF
C Programming - Refresher - Part IV
Emertxe Information Technologies Pvt Ltd
 
PDF
Learn this at any cost of Physics for engineering Physics
Aariz2
 
Unit 1
donny101
 
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
babasahebgaikwad8
 
Introduction-to-C-Programming (1ggggggggggggggggg).pptx
middollaganeshreddy0
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Ovidiu Farauanu
 
TAPASH kumar das its my college pptasjhk
destroyer7992
 
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Selvaraj Seerangan
 
C programming basic concepts of mahi.pptx
KorbanMaheshwari
 
OOP UNIT 1_removed ppt explaining object.pdf
rajbaibhav004
 
Lecture 3.mte 407
rumanatasnim415
 
DSD Unit 1 Abstract Data Type data structures design notes.pptx
yuvaraniit
 
SE-IT JAVA LAB OOP CONCEPT
nikshaikh786
 
Basic Concepts of C Language.pptx
KorbanMaheshwari
 
Frequently asked tcs technical interview questions and answers
nishajj
 
Introduction-to-Python-for-better-knowledge-
singh08ravinder
 
Data Types in C++-Primary or Built-in or Fundamental data type Derived data t...
ssuser5610081
 
Unit-5.1.pptx programing in c language lesson 5
BhumiMakkar
 
Fundamentals of Data Structures Unit 1.pptx
Vigneshkumar Ponnusamy
 
venkatesh.pptx
KishoreRedla
 
C Programming - Refresher - Part IV
Emertxe Information Technologies Pvt Ltd
 
Learn this at any cost of Physics for engineering Physics
Aariz2
 
Ad

More from wajihaabbas95 (9)

PPTX
Ethnocentrism_and_Cultural_Relations_Presentation.pptx
wajihaabbas95
 
PDF
Ethnocentrism and cultural relativism.pdf
wajihaabbas95
 
PPTX
Zainab 5017 English presentation. .pptx.
wajihaabbas95
 
PPTX
Memory and Processor for class presentation.pptx
wajihaabbas95
 
PPTX
English presentation for university students.pptx
wajihaabbas95
 
PPT
English presentation common noun proper noun
wajihaabbas95
 
PPTX
SOFTWARE ENGINEERING FINAL PRESEBTATION.pptx
wajihaabbas95
 
PPTX
Limitations of paragraph writing newone.pptx
wajihaabbas95
 
PDF
Presentation%20(5)%20(1) (1).pdf university of okara
wajihaabbas95
 
Ethnocentrism_and_Cultural_Relations_Presentation.pptx
wajihaabbas95
 
Ethnocentrism and cultural relativism.pdf
wajihaabbas95
 
Zainab 5017 English presentation. .pptx.
wajihaabbas95
 
Memory and Processor for class presentation.pptx
wajihaabbas95
 
English presentation for university students.pptx
wajihaabbas95
 
English presentation common noun proper noun
wajihaabbas95
 
SOFTWARE ENGINEERING FINAL PRESEBTATION.pptx
wajihaabbas95
 
Limitations of paragraph writing newone.pptx
wajihaabbas95
 
Presentation%20(5)%20(1) (1).pdf university of okara
wajihaabbas95
 
Ad

Recently uploaded (20)

PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
PDF
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Autodock-for-Beginners by Rahul D Jawarkar.pptx
Rahul Jawarkar
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Sandeep Swamy
 
RA 12028_ARAL_Orientation_Day-2-Sessions_v2.pdf
Seven De Los Reyes
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 

programming presentation group 7 ppt..pdf

  • 1. Presentation. Programming Submitted by Saad Lodhi Nabiha Rana Dua Safdar Muqaddas Hanif Submitted to Mam Faiza
  • 2. Pointer A pointer is a variable in programming languages, particularly C and C++, that stores the memory address of another variable. Pointers are a powerful feature of these languages because they provide direct access to memory and allow for efficient manipulation of data structures and dynamic memory allocation.
  • 3. Functions of pointer 1. Direct Memory Access: Pointers enable direct manipulation of memory, which can improve performance for certain operations by eliminating the need to copy data 1. Dynamic Memory Allocation: Pointers are essential for allocating memory dynamically using functions like malloc and free in C, and new and delete in C++.
  • 4. Functions of pointer Data Structures: Pointers are used to implement complex data structures such as linked lists, trees, and graphs. 3Function Arguments: Pointers can be used to pass large amounts of data to functions efficiently by passing the address of the data rather than the data itself. 3
  • 5. Functions of pointer Array Management: Pointers provide efficient ways to iterate through arrays and manipulate array elements. Pointer Arithmetic: Allows for navigation through memory blocks, which is useful for various algorithms and operations.
  • 6. Types of pointer Null Pointer: A pointer that is initialized to NULL or 0. It does not point to any valid memory location.int *ptr = NULL; Void Pointer (Generic Pointer): A special type of pointer that can point to any data type. It is often used for generic functions.void *ptr; Dangling Pointer: A pointer that points to a memory location that has been freed or deallocated. Using a dangling pointer can lead to undefined behavior.int *ptr = (int *)malloc(sizeof(int)); free(ptr); // ptr is now a dangling pointer Wild Pointer: An uninitialized pointer that can contain any arbitrary address. Using wild pointers can result in unpredictable behavior.int *ptr; // ptr is a wild pointer 1 2 3 4
  • 7. Usage and deceleration Pointer Declarationint *ptr; // Declares a pointer to an integer char *ptr; // Declares a pointer to a character • Pointer Initializationint x = 10; • int *ptr = &x; // ptr now holds the address of x • Dereferencing a PointerDereferencing a pointer means accessing the value stored at the memory address the pointer is pointing to.int x = 10; • int *ptr = &x; • printf(“%d”, *ptr); // Outputs 10 Pointer ArithmeticPointer arithmetic involves operations like addition and subtraction on pointers, typically used for iterating through arrays.int arr[] = {10, 20, 30, 40, 50}; int *ptr = arr; printf(“%d”, *(ptr + 2)); // Outputs 30
  • 8. Conclusion Pointers are a fundamental aspect of C and C++ programming, providing powerful capabilities for memory management, data structure manipulation, and efficient function calling. However, they require careful handling due to the potential for errors and undefined behavior. Understanding pointers and their various types and functions is essential for mastering low-level programming and system design.
  • 9. Reference Reference is a value that enables a program to indirectly access a particular piece of data stored in memory. Rather than containing the actual data itself, a reference contains information about the location of the data, which can be an object, variable, array, or function. Characteristics of reference • Indirect Access: References allow access to data indirectly by storing the memory address where the data is located.
  • 10. Characteristics of reference • Abstraction: References abstract away the direct manipulation of memory addresses, making code safer and easier to read. • Immutable Binding: In many languages, once a reference is set to point to a particular data object, it cannot be changed to point to a different object.
  • 11. Reference types of programming language Java:In Java, all non-primitive types (objects, arrays) are reference types.String str = “Hello”; int[] numbers = {1, 2, 3}; • C#:C# uses reference types for classes, arrays, delegates, and more.Person person = new Person(); • int[] numbers = {1, 2, 3}; C++:C++ supports both references and pointers, but references are generally safer and used for parameter passing and return values.int x = 10; int &ref = x; // ref is a reference to x
  • 12. Example of reference usage Example of Reference UsageJava Examplepublic class ReferenceExample { public static void main(String[] args) { Person person1 = new Person(“Alice”); Person person2 = person1; // person2 is a reference to the same Person object as person1 person2.setName(“Bob”); System.out.println(person1.getName()); // Outputs “Bob” } } class Person { private String name; public Person(String name) {
  • 13. Continue….. .. This.name = name; } public void setName(String name) { this.name = name; } public String getName() { return name; } } In this example:person1 and person2 both reference the same Person object.Changing the name via person2 also reflects when accessing the name via person1, demonstrating shared access to the object.
  • 14. Conclusion ConclusionReferences are a fundamental concept in programming that enable efficient, indirect access to data. They are widely used in object- oriented programming, parameter passing, and the implementation of dynamic data structures. Understanding how references work and how to use them effectively is crucial for developing robust and efficient software.
  • 15. Memory allocation Definition Memory allocation in programming refers to the process of reserving a portion of computer memory for the storage of data during the execution of a program. Types of memory allocation 1 SMA 2DMA
  • 16. Static memory allocation Definition • Static memory allocation is a method of allocating memory at compile time before the associated program is executed. The memory allocated using static memory allocation is fixed and cannot be changed during the runtime of the program. This type of allocation is typically used for global variables, static variables, and constants.
  • 17. Advantages of static memory allocation • Predictability:Since memory is allocated at compile time, the program’s memory requirements are known beforehand, making it easier to manage resources. • No Fragmentation:Static memory allocation does not suffer from fragmentation issues, which are common in dynamic memory allocation. • Runtime Efficiency:There is no need for runtime memory allocation and deallocation, reducing the overhead and potential runtime errors. • Simplicity:Static allocation is simpler to implement and understand, reducing the complexity of memory management.
  • 18. Characteristics of static memory Compile-Time Allocation:Memory is allocated during the compilation of the program.The size and type of memory allocation are known beforehand, making it predictable. • Fixed Size:The size of the allocated memory block is fixed and cannot be altered at runtime.This means the programmer must know the required memory size in advance. • Efficiency:Because the memory is allocated at compile time, there is no runtime overhead for memory allocation and deallocation.This can lead to more efficient memory usage for certain types of applications.
  • 19. Example • Example of Static Memory AllocationGlobal VariablesIn C and C++, global variables are allocated statically.#include <stdio.h> • • int globalVar = 10; // Statically allocated global variable • • void display() { • printf(“Global Variable: %dn”, globalVar); • } • • int main() { • display(); • return 0; • }
  • 20. Conclusion • ConclusionStatic memory allocation is a fundamental concept in programming where memory is allocated at compile time. It offers predictability, efficiency, and simplicity, making it suitable for scenarios where memory requirements are well-defined and constant. However, its lack of flexibility and potential for memory waste limit its applicability in dynamic and complex applications. Understanding static memory allocation is crucial for efficient resource management and optimal program performance in various programming contexts.
  • 21. Dynamic memory allocation Definition Dynamic memory allocation is a type of memory allocation which provides memory during the time of allocation Dynamic memory allocation refers to the process of allocating memory at runtime as opposed to compile time. This allows programs to request memory as needed and release it when it is no longer required, enabling efficient use of memory for varying data sizes and structures. Dynamic memory allocation is crucial for implementing flexible data structures like linked lists, trees, and more.
  • 22. Types of dynamic memory allocation There are four types of dynamic memory allocation
  • 23. Malloc Function Header file for DMA (Stdlib. h) Definition: Melloc function create a single block of give size . During the time of allocation . Syntax: Pre= {data type} malloc (size of) Example: Ptr= (intr*) malloc (n*size of(intr)}
  • 24. Calloc…. … Definition • Create bunch of blocks of given size during the time of allocation Syntax: • Ptr= (data type*)collac(sizeof) Example: Ptr= (intr*) calloc (n, sizeof{intr})
  • 25. Realloc… … Definition: • Realloc function recreates already created blocks of given size. Syntax: • Ptr: (data type) realloc (old ptr new sizeof) Example: Ptr(data type*) realloc (ptr,n*sizeof(intr)}
  • 26. Free()… … Definition Free () function deletes the allocated memory . • During the time of allocation. Syntax Free (pointer) Example: Free(ptr)