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

Pointer C++

pointer

Uploaded by

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

Pointer C++

pointer

Uploaded by

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

23CS101 - Problem Solving Using C++

Study Materials
Pointers:

• Pointers are symbolic representations of addresses. They enable programs to


simulate call-by-reference as well as to create and manipulate dynamic data
structures.
• Iterating over elements in arrays or other data structures is one of the main use
of pointers.
• The address of the variable you’re working with is assigned to the pointer
variable that points to the same data type (such as an int or string).
• Syntax:
Pointers works:
How to use a pointer?:

• Define a pointer variable


• Assigning the address of a variable to a pointer using the unary operator (&)
which returns the address of that variable.
• Accessing the value stored in the address using unary operator (*) which returns
the value of the variable located at the address specified by its operand.
Pointers:
References and Pointers:

• There are 3 ways to pass C++ arguments to a function:


• Call-By-Value
• Call-By-Reference with a Pointer Argument
• Call-By-Reference with a Reference Argument
Memory Allocation:

• Memory allocation is basically a way of booking a partial or entire part of system


memory space for the execution of applications.
• Memory allocation may be executed through a method known as memory
management.
• There are two types of memory spaces in our device- static memory and dynamic
memory.
• Static Memory
• Dynamic Memory
Dynamic Memory Allocation:

• Memory allocation during runtime using pointers.


• Allows for flexible memory use.

• Using new and delete:


• int *p = new int; // Allocates memory for an integer.
• delete p; // Deallocates memory pointed to by p.

• Using new[] and delete[]:


• int *arr = new int[5]; // Allocates an array of 5 integers.
• delete[] arr; // Deallocates the array.
Memory Allocation:

• Static Memory: In static memory allocation, memory is allotted and deallocated


by the compiler on its very own.
• It's miles of permanent space allotted through the operating system which
speeds up the time of execution of a program.
• We want to outline the required size of memory and it cannot reallocate the
memory storage space consumed by means of the program until its execution is
over.
Dynamic Memory Allocation:

• Dynamic Memory: In dynamic allocation, the allocation and deallocation of the


memory happen at runtime. That is, the memory must be allocated or de-
allocated by the program all through the run-time of a C++ program.
• So the programmer is required to deallocate the dynamically allocated memory
which is not in use.
Array:
Memory Allocation:

You might also like