SlideShare a Scribd company logo
ARRAY IN C++
-VARSHAA.M
MAHESHA.V
WHAT IS ARRAY?
• An array is a group of consective memory
locations with same name and data type.
• Simple variable is a single memory location with
unique name and a type. But an Array is
collection of different adjacent memory
locations. All these memory locations have one
collective name and type.
• The memory locations in the array are known as
elements of array. The total number of elements
in the array is called length.
• The elements of array is accessed with
reference to its position in array, that is call
index or subscript.
DECLARATION OF AN ARRAY:
Like a regular variable, an array must be declared
before it is used. A typical declaration for an array in
Visual C++ is:
type name [elements];
 type is a valid type (like int, float...)
 name is a valid identifier
 elements field (which is always enclosed in square
brackets []), specifies how many of these elements
the array has to contain.
EXPLANATION:
INT NUM[6]
size of
the
array
Base name of
type array
ADVANTAGES OF ARRAY:
 Arrays can store a large number of value
with single name.
 Arrays are used to process many value
easily and quickly.
 The values stored in an array can be
sorted easily.
 The search process can be applied on
arrays easily.
EG. PROGRAM:
TYPES OF ARRAY:
Single dimensional array
Two dimensional array
Multi dimensional array
ONE DIMENSIONAL ARRAY:
A one dimensional array is one in which one
subscript /indices specification is needed to
specify a particular element of array
Declaration :
Data_type array_name [size of array ];
Eg:
Int num[10];
EXAMPLE PROGRAM:
MEMORY REPRESENTATION:
num[0] num[1] num[2] num[3] num[4] num[5] num[6] num[7] num[8] num[9]
2000 2002 2004 2006 2008 2010 2012 2014 2016 2018
starting Address of location
Total memory in bytes that an array is occupied :
Size of array=size of array*size of(base type)
Hear,
10*2=20
39 56 23 98 6 56 9 2 54 67
TWO DIMENSIONAL ARRAY:
A 2-d array is an array in which each element is
itself an array
i.e int num[4][3]
0 1 2
0
1
2
3
No of
rows
No
of
colu
mns
No of element in
2-D array =M*N
Num [2][1]
EXAMPLE PROGRAM:
MEMORY REPRESENTATION:
Total bytes= no of rows*no of columns*size of(base type)
Memory reprsentation in 2-D array:
char A [2][3]
A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2]
5001 5002 5003 5004 5005 5006
MULTI DIMENSIONAL ARRAY:
An array with dimensions more than
two .The maximum limit of array is compiler
dependent
Declaration:
Data_type name [a][b][c][d][e][f]…….[n];
Array of 3 or more dimensional are not often
use because of huge memory requirement
and complexity involved
EXAMPLE PROGRAMS:
ARRAY INITIALIZATION:
C++ provides the facility of array initialization at the time of
declaration .General form of array initialization is as:
Type array_name[size 1]…..[size N] ={vale list};
Eg:
Int days_month[12]={31,25,29,03,31,19,20,31,18,20,31,29};
Char string[6]={‘a’,’r’,’g’,’y’,’d’,’0’};
2-D array are also initialized in same way as linear array
Int cube[4][2]={ 1,3,
4,6,
9,37,
5,78
};
UNSIZED ARRAY INITIALIZATION:
C++ allowed you to skip the size of array in an array initialization
statement C++ automatically create an array big enough to hold all
the initializers present
Char S1[] =“ first string ”;
you skip the size, you must give list of initializers so that C++ can
calculate the size of array
Int val []={3,5,6,2,8,9,6,4};
Int cube [] [2] ={ 1,3,
67,7,
6,87,
};
STRING AS ARRAY:
C++ does not have a String data type ,it
impairments string as 1-D character Arrray .A
string as a character array is terminate by a
null character ‘0’
Char str 1 [11];
Char square [][]={ ‘first string’,
‘second string’,
‘third string’
};
SORTING ARRAYS:
Sorting is a process of arranging
the value of array in a particular
order. An array can be sorted in
two order.
o Ascending Order
o Descending Order
THANK YOU
String
 C++ strings are sequences of characters stored in a char
array.
 Strings are used to store words and text.
 String index starts with o last character of string in
null(0)
 Strings in C++ can be defined either using
the std::string class or the C-style character arrays.
C Style Strings
 These strings are stored as the plain old array of
characters terminated by a null character ‘0’. They
are the type of strings that C++ inherited from C
language.
 Syntax:
 Char str[]=“greeksforgreeks”
 // C++ Program to demonstrate strings
 #include <iostream>
 using namespace std;
 int main()
 {
 char s[] = "GeeksforGeeks";
 cout << s << endl;
 return 0;
 }
 Output:GreeksforGreeks
 std::string Class
 These are the new types of strings that are introduced
in C++ as std::string class defined inside <string> header
file. This provides many advantages over conventional
C-style strings such as dynamic size, member functions,
etc.
 Syntax:std::string str("GeeksforGeeks");
String manipulator functions
 C++ supports a wide range of functions that
manipulate null-terminated strings. These are:
 strcpy(str1, str2): Copies string str2 into string
str1.
 strcat(str1, str2): Concatenates string str2 onto
the end of string str1.
 strlen(str1): Returns the length of string str1.
 strcmp(str1, str2): Returns 0 if str1 and str2 are
the same; less than 0 if str1<str2; greater than 0 if
str1>str2.
 strchr(str1, ch): Returns a pointer to the first
occurrence of character ch in string str1.
 strstr(str1, str2): Returns a pointer to the first
occurrence of string str2 in string str1.
Pointer
 Pointer is a variable that holds the memory address of
another variable.
 Declaration of array is
 datataype *pointer-variable;
 Pointer variable is the name of the pointer, datatype
refers to valid c++ datatypes.
 Int *ptr,a; //declaration
 Ptr=&a; //initialization
 Ptr contains address of variabler a,& is addess operator
or reference operator to retrieve the address of the
variable.
 Example int a=10;
 int *ptr=&a;
Pointer arithmetic
 Pointer arithmetic means performing arithmetic
operations on pointers. It refers to the operations that
are valid to perform on pointers. Following are the
arithmetic operations valid on pointers in C++:
 Incrementing and Decrementing Pointers
 Addition of Constant to Pointers
 Subtraction of Constant from Pointers
 Subtraction of Two Pointers of the Same Type
 Comparison of Pointers
 Incrementing and Decrementing Pointer in C++
 Incrementing or decrementing a pointer will make it
refer to the address of the next or previous data in the
memory. This process differs from incrementing and
decrementing numeric data.
Incrementing a Pointer
 Incrementing a pointer will depend on the type of
variable address stored in the pointer. If the pointer
stored the address of the integer type variable then the
size of the integer pointer can be 4 bytes.
 For example, If a pointer holds the address 1000 and
we increment the pointer, then the pointer will be
incremented by 4 or 8 bytes (size of the integer), and
the pointer will now hold the address 1004.
 Decrementing a Pointer
 When we apply a decrement operation on the pointer
then the pointer is decremented by 4 or 8 bytes
depending upon the machine.
 For example, If a pointer holds the address 1004 and
we decrement the pointer, then the pointer will be
decremented by 4 or 8 bytes (size of the integer), and
the pointer will now hold the address 1000.
 Memory
996 997 998 999 1000 1001 1002 1003 1004
 Addition of Constant to Pointers
 We can add integer values to Pointers and the pointer is
adjusted based on the size of the data type it points to.
For example, if an integer pointer stores the address
1000 and we add the value 5 to the pointer, it will store
the new address as:
 Memory
1000 1004 1008 1012 1016 1020 1024 1028 1032
1000 + (5 * 4(size of an integer)) = 1020
 Subtraction of Constant from Pointers
 We can also subtract a constant from Pointers and it is
the same as the addition of a constant to a pointer. For
example, if an integer pointer stores the address 1000
and we subtract the value 5 from the pointer, it will
store the new address as:
 1000 - (5 * 4(size of an integer)) = 980
 Subtraction of Two Pointers of the Same Datatype
 The Subtraction of two pointers can be done only when
both pointers are of the same data type. The
subtraction of two pointers gives the number of
elements present between the two pointers
 Comparison of Pointers
 In C++, we can perform a comparison between the two
pointers using the relational operators(>, <, >=, <=, ==,
!=). We generally use this operation to check whether
the two-pointer as pointing to the same memory
location or not.

More Related Content

Similar to arraytypes of array and pointer string in c++.pptx (20)

Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
lecture-05_Arrays_Strings_Pointers in C++.pdf
lecture-05_Arrays_Strings_Pointers  in C++.pdflecture-05_Arrays_Strings_Pointers  in C++.pdf
lecture-05_Arrays_Strings_Pointers in C++.pdf
hunegnawwondatir
 
Arrays & Strings.pptx
Arrays & Strings.pptxArrays & Strings.pptx
Arrays & Strings.pptx
AnkurRajSingh2
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Pointer
PointerPointer
Pointer
manish840
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
Mukund Trivedi
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
JumanneChiyanda
 
Pointers in C++ object oriented programming
Pointers in C++ object oriented programmingPointers in C++ object oriented programming
Pointers in C++ object oriented programming
Ahmad177077
 
Structured Data Type Arrays
Structured Data Type ArraysStructured Data Type Arrays
Structured Data Type Arrays
Praveen M Jigajinni
 
Array In C++ programming object oriented programming
Array In C++ programming object oriented programmingArray In C++ programming object oriented programming
Array In C++ programming object oriented programming
Ahmad177077
 
8 Pointers
8 Pointers8 Pointers
8 Pointers
Praveen M Jigajinni
 
Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .
karimibaryal1996
 
1-Intoduction ------------- Array in C++
1-Intoduction ------------- Array in C++1-Intoduction ------------- Array in C++
1-Intoduction ------------- Array in C++
ab6399671
 
DSA-Lecture03-Pointers, Strings(outputs).pptx
DSA-Lecture03-Pointers, Strings(outputs).pptxDSA-Lecture03-Pointers, Strings(outputs).pptx
DSA-Lecture03-Pointers, Strings(outputs).pptx
mubashirahmed0296
 
C++.pptx
C++.pptxC++.pptx
C++.pptx
Sabi995708
 
Chapter 3 summaryv2(Pointers) in c++.pptx
Chapter 3 summaryv2(Pointers) in c++.pptxChapter 3 summaryv2(Pointers) in c++.pptx
Chapter 3 summaryv2(Pointers) in c++.pptx
TheAdventure5
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
C++ Pointer | Introduction to programming
C++ Pointer | Introduction to programmingC++ Pointer | Introduction to programming
C++ Pointer | Introduction to programming
mahidazad00
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
sandhya yadav
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
lecture-05_Arrays_Strings_Pointers in C++.pdf
lecture-05_Arrays_Strings_Pointers  in C++.pdflecture-05_Arrays_Strings_Pointers  in C++.pdf
lecture-05_Arrays_Strings_Pointers in C++.pdf
hunegnawwondatir
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
JumanneChiyanda
 
Pointers in C++ object oriented programming
Pointers in C++ object oriented programmingPointers in C++ object oriented programming
Pointers in C++ object oriented programming
Ahmad177077
 
Array In C++ programming object oriented programming
Array In C++ programming object oriented programmingArray In C++ programming object oriented programming
Array In C++ programming object oriented programming
Ahmad177077
 
Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .Introduction to pointers in c plus plus .
Introduction to pointers in c plus plus .
karimibaryal1996
 
1-Intoduction ------------- Array in C++
1-Intoduction ------------- Array in C++1-Intoduction ------------- Array in C++
1-Intoduction ------------- Array in C++
ab6399671
 
DSA-Lecture03-Pointers, Strings(outputs).pptx
DSA-Lecture03-Pointers, Strings(outputs).pptxDSA-Lecture03-Pointers, Strings(outputs).pptx
DSA-Lecture03-Pointers, Strings(outputs).pptx
mubashirahmed0296
 
Chapter 3 summaryv2(Pointers) in c++.pptx
Chapter 3 summaryv2(Pointers) in c++.pptxChapter 3 summaryv2(Pointers) in c++.pptx
Chapter 3 summaryv2(Pointers) in c++.pptx
TheAdventure5
 
Data Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasdData Structures asdasdasdasdasdasdasdasdasdasd
Data Structures asdasdasdasdasdasdasdasdasdasd
abdulrahman39ab
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
Manisha Keim
 
C++ Pointer | Introduction to programming
C++ Pointer | Introduction to programmingC++ Pointer | Introduction to programming
C++ Pointer | Introduction to programming
mahidazad00
 

More from harinipradeep15 (7)

architecture design and implementation.pptx
architecture design and implementation.pptxarchitecture design and implementation.pptx
architecture design and implementation.pptx
harinipradeep15
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).pptchapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Introduction to c++ programming language
Introduction to c++ programming languageIntroduction to c++ programming language
Introduction to c++ programming language
harinipradeep15
 
SE_L7systemmodel software engineering.pptx
SE_L7systemmodel software engineering.pptxSE_L7systemmodel software engineering.pptx
SE_L7systemmodel software engineering.pptx
harinipradeep15
 
6_Object-oriented-using-java.pdf object oriented programming concepts
6_Object-oriented-using-java.pdf object oriented programming concepts6_Object-oriented-using-java.pdf object oriented programming concepts
6_Object-oriented-using-java.pdf object oriented programming concepts
harinipradeep15
 
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptxINTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
harinipradeep15
 
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptxINTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
harinipradeep15
 
architecture design and implementation.pptx
architecture design and implementation.pptxarchitecture design and implementation.pptx
architecture design and implementation.pptx
harinipradeep15
 
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).pptchapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
chapterintroductiontomodularprogramming-230112092330-e3eb5a74 (1).ppt
harinipradeep15
 
Introduction to c++ programming language
Introduction to c++ programming languageIntroduction to c++ programming language
Introduction to c++ programming language
harinipradeep15
 
SE_L7systemmodel software engineering.pptx
SE_L7systemmodel software engineering.pptxSE_L7systemmodel software engineering.pptx
SE_L7systemmodel software engineering.pptx
harinipradeep15
 
6_Object-oriented-using-java.pdf object oriented programming concepts
6_Object-oriented-using-java.pdf object oriented programming concepts6_Object-oriented-using-java.pdf object oriented programming concepts
6_Object-oriented-using-java.pdf object oriented programming concepts
harinipradeep15
 
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptxINTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
INTRODUCTION TO DATABASE MANAGEMENT SYSTEM.pptx
harinipradeep15
 
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptxINTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
INTRODUCTION TO SOFTWARE ENGINEERINNG new 2.pptx
harinipradeep15
 
Ad

Recently uploaded (20)

Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Simplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for ContractorsSimplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for Contractors
SHEQ Network Limited
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Safe Software
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Topic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptxTopic 26 Security Testing Considerations.pptx
Topic 26 Security Testing Considerations.pptx
marutnand8
 
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfThe Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdf
Varsha Nayak
 
Simplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for ContractorsSimplify Training with an Online Induction Portal for Contractors
Simplify Training with an Online Induction Portal for Contractors
SHEQ Network Limited
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Scaling FME Flow on Demand with Kubernetes: A Case Study At Cadac Group SaaS ...
Safe Software
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink TemplateeeeeeeeeeeeeeeeeeeeeeeeeeNeuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
Neuralink Templateeeeeeeeeeeeeeeeeeeeeeeeee
alexandernoetzold
 
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...
WSO2
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
Eliminate the complexities of Event-Driven Architecture with Domain-Driven De...
SheenBrisals
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps CyclesFrom Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
From Chaos to Clarity - Designing (AI-Ready) APIs with APIOps Cycles
Marjukka Niinioja
 
Content Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ ProductivityContent Mate Web App Triples Content Managers‘ Productivity
Content Mate Web App Triples Content Managers‘ Productivity
Alex Vladimirovich
 
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptxIMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
IMAGE CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK.P.pptx
usmanch7829
 
Ad

arraytypes of array and pointer string in c++.pptx

  • 2. WHAT IS ARRAY? • An array is a group of consective memory locations with same name and data type. • Simple variable is a single memory location with unique name and a type. But an Array is collection of different adjacent memory locations. All these memory locations have one collective name and type. • The memory locations in the array are known as elements of array. The total number of elements in the array is called length. • The elements of array is accessed with reference to its position in array, that is call index or subscript.
  • 3. DECLARATION OF AN ARRAY: Like a regular variable, an array must be declared before it is used. A typical declaration for an array in Visual C++ is: type name [elements];  type is a valid type (like int, float...)  name is a valid identifier  elements field (which is always enclosed in square brackets []), specifies how many of these elements the array has to contain.
  • 5. ADVANTAGES OF ARRAY:  Arrays can store a large number of value with single name.  Arrays are used to process many value easily and quickly.  The values stored in an array can be sorted easily.  The search process can be applied on arrays easily.
  • 7. TYPES OF ARRAY: Single dimensional array Two dimensional array Multi dimensional array
  • 8. ONE DIMENSIONAL ARRAY: A one dimensional array is one in which one subscript /indices specification is needed to specify a particular element of array Declaration : Data_type array_name [size of array ]; Eg: Int num[10];
  • 10. MEMORY REPRESENTATION: num[0] num[1] num[2] num[3] num[4] num[5] num[6] num[7] num[8] num[9] 2000 2002 2004 2006 2008 2010 2012 2014 2016 2018 starting Address of location Total memory in bytes that an array is occupied : Size of array=size of array*size of(base type) Hear, 10*2=20 39 56 23 98 6 56 9 2 54 67
  • 11. TWO DIMENSIONAL ARRAY: A 2-d array is an array in which each element is itself an array i.e int num[4][3] 0 1 2 0 1 2 3 No of rows No of colu mns No of element in 2-D array =M*N Num [2][1]
  • 13. MEMORY REPRESENTATION: Total bytes= no of rows*no of columns*size of(base type) Memory reprsentation in 2-D array: char A [2][3] A[0][0] A[0][1] A[0][2] A[1][0] A[1][1] A[1][2] 5001 5002 5003 5004 5005 5006
  • 14. MULTI DIMENSIONAL ARRAY: An array with dimensions more than two .The maximum limit of array is compiler dependent Declaration: Data_type name [a][b][c][d][e][f]…….[n]; Array of 3 or more dimensional are not often use because of huge memory requirement and complexity involved
  • 16. ARRAY INITIALIZATION: C++ provides the facility of array initialization at the time of declaration .General form of array initialization is as: Type array_name[size 1]…..[size N] ={vale list}; Eg: Int days_month[12]={31,25,29,03,31,19,20,31,18,20,31,29}; Char string[6]={‘a’,’r’,’g’,’y’,’d’,’0’}; 2-D array are also initialized in same way as linear array Int cube[4][2]={ 1,3, 4,6, 9,37, 5,78 };
  • 17. UNSIZED ARRAY INITIALIZATION: C++ allowed you to skip the size of array in an array initialization statement C++ automatically create an array big enough to hold all the initializers present Char S1[] =“ first string ”; you skip the size, you must give list of initializers so that C++ can calculate the size of array Int val []={3,5,6,2,8,9,6,4}; Int cube [] [2] ={ 1,3, 67,7, 6,87, };
  • 18. STRING AS ARRAY: C++ does not have a String data type ,it impairments string as 1-D character Arrray .A string as a character array is terminate by a null character ‘0’ Char str 1 [11]; Char square [][]={ ‘first string’, ‘second string’, ‘third string’ };
  • 19. SORTING ARRAYS: Sorting is a process of arranging the value of array in a particular order. An array can be sorted in two order. o Ascending Order o Descending Order
  • 21. String  C++ strings are sequences of characters stored in a char array.  Strings are used to store words and text.  String index starts with o last character of string in null(0)  Strings in C++ can be defined either using the std::string class or the C-style character arrays.
  • 22. C Style Strings  These strings are stored as the plain old array of characters terminated by a null character ‘0’. They are the type of strings that C++ inherited from C language.  Syntax:  Char str[]=“greeksforgreeks”
  • 23.  // C++ Program to demonstrate strings  #include <iostream>  using namespace std;  int main()  {  char s[] = "GeeksforGeeks";  cout << s << endl;  return 0;  }  Output:GreeksforGreeks
  • 24.  std::string Class  These are the new types of strings that are introduced in C++ as std::string class defined inside <string> header file. This provides many advantages over conventional C-style strings such as dynamic size, member functions, etc.  Syntax:std::string str("GeeksforGeeks");
  • 25. String manipulator functions  C++ supports a wide range of functions that manipulate null-terminated strings. These are:  strcpy(str1, str2): Copies string str2 into string str1.  strcat(str1, str2): Concatenates string str2 onto the end of string str1.  strlen(str1): Returns the length of string str1.  strcmp(str1, str2): Returns 0 if str1 and str2 are the same; less than 0 if str1<str2; greater than 0 if str1>str2.  strchr(str1, ch): Returns a pointer to the first occurrence of character ch in string str1.  strstr(str1, str2): Returns a pointer to the first occurrence of string str2 in string str1.
  • 26. Pointer  Pointer is a variable that holds the memory address of another variable.  Declaration of array is  datataype *pointer-variable;  Pointer variable is the name of the pointer, datatype refers to valid c++ datatypes.
  • 27.  Int *ptr,a; //declaration  Ptr=&a; //initialization  Ptr contains address of variabler a,& is addess operator or reference operator to retrieve the address of the variable.  Example int a=10;  int *ptr=&a;
  • 28. Pointer arithmetic  Pointer arithmetic means performing arithmetic operations on pointers. It refers to the operations that are valid to perform on pointers. Following are the arithmetic operations valid on pointers in C++:  Incrementing and Decrementing Pointers  Addition of Constant to Pointers  Subtraction of Constant from Pointers  Subtraction of Two Pointers of the Same Type  Comparison of Pointers
  • 29.  Incrementing and Decrementing Pointer in C++  Incrementing or decrementing a pointer will make it refer to the address of the next or previous data in the memory. This process differs from incrementing and decrementing numeric data.
  • 30. Incrementing a Pointer  Incrementing a pointer will depend on the type of variable address stored in the pointer. If the pointer stored the address of the integer type variable then the size of the integer pointer can be 4 bytes.  For example, If a pointer holds the address 1000 and we increment the pointer, then the pointer will be incremented by 4 or 8 bytes (size of the integer), and the pointer will now hold the address 1004.
  • 31.  Decrementing a Pointer  When we apply a decrement operation on the pointer then the pointer is decremented by 4 or 8 bytes depending upon the machine.  For example, If a pointer holds the address 1004 and we decrement the pointer, then the pointer will be decremented by 4 or 8 bytes (size of the integer), and the pointer will now hold the address 1000.
  • 32.  Memory 996 997 998 999 1000 1001 1002 1003 1004
  • 33.  Addition of Constant to Pointers  We can add integer values to Pointers and the pointer is adjusted based on the size of the data type it points to. For example, if an integer pointer stores the address 1000 and we add the value 5 to the pointer, it will store the new address as:
  • 34.  Memory 1000 1004 1008 1012 1016 1020 1024 1028 1032 1000 + (5 * 4(size of an integer)) = 1020
  • 35.  Subtraction of Constant from Pointers  We can also subtract a constant from Pointers and it is the same as the addition of a constant to a pointer. For example, if an integer pointer stores the address 1000 and we subtract the value 5 from the pointer, it will store the new address as:  1000 - (5 * 4(size of an integer)) = 980
  • 36.  Subtraction of Two Pointers of the Same Datatype  The Subtraction of two pointers can be done only when both pointers are of the same data type. The subtraction of two pointers gives the number of elements present between the two pointers
  • 37.  Comparison of Pointers  In C++, we can perform a comparison between the two pointers using the relational operators(>, <, >=, <=, ==, !=). We generally use this operation to check whether the two-pointer as pointing to the same memory location or not.