SlideShare a Scribd company logo
1 of 3
Discuss how to pass the address of an array to a function and provide an example. Please do not
write a complete programming code, only briefly discuss the process and provide a simple
example.
Solution
Passing an array to a funciton is of two types.
1.Passing the array name to the function
2.Passing the address of array name to the function
In both the cases, the function takes the address of the first element of array name.
Array name itself represents the address of starting element the array.
---------------------------------------------------------------------------------------------------------------------
---------
/**
Test program to illustrate the passing an array to a funciton.
*/
#include<iostream>
using namespace std;
//function header types
void printUsingPointer(int *arrPtr,int SIZE);
void printUsingArray(int arr[],int SIZE);
int main()
{
//constant size
const int SIZE=5;
//an array of type integer and stores values
int arr[5]={2,3,4,5,6};
/**
The function printUsingArray takes the address of the first argument as input argument
to the funciton when calling the function
*/
cout<<"Printing array using array notation :"<<endl;
//call function printUsingPointer with array,arr and SIZE
printUsingArray(arr,SIZE);
//create a pointer and assign the address of the starting element of array,arr
int *arrPtr=arr;
cout<<" Printing array using pointer notation :"<<endl;
//call function printUsingPointer with pointer, arrPtr and SIZE
printUsingPointer(arrPtr,SIZE);
system("pause");
return 0;
}
/**The function printUsingPointer that takes an array pointer(reference value) and size
and print the values using pointer notation where * represents an indirection operator
that returns the value at address of arrPtr+index
*/
void printUsingPointer(int *arrPtr, int size)
{
for(int index=0;index<size;index++)
cout<<*(arrPtr+index)<<" ";
}
/**The function printUsingArray that takes an array and size
and print the values using array notation, arr[index]
*/
void printUsingArray(int arr[],int size)
{
for(int index=0;index<size;index++)
cout<<arr[index]<<" ";
}
-------------------------------------------------------------------
sample output:
Printing array using array notation :
2 3 4 5 6
Printing array using pointer notation :
2 3 4 5 6
Discuss how to pass the address of an array to a function and provide.docx

More Related Content

Similar to Discuss how to pass the address of an array to a function and provide.docx

C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick reviewCe.Se.N.A. Security
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interviewRussell Childs
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayPhil Estes
 
SystemVerilog-20041201165354.ppt
SystemVerilog-20041201165354.pptSystemVerilog-20041201165354.ppt
SystemVerilog-20041201165354.pptravi446393
 
There are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfThere are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfaparnatiwari291
 
Introduction to apache_cassandra_for_develope
Introduction to apache_cassandra_for_developeIntroduction to apache_cassandra_for_develope
Introduction to apache_cassandra_for_developezznate
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfnewfaransportsfitnes
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Meghaj Mallick
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packagesAjay Ohri
 

Similar to Discuss how to pass the address of an array to a function and provide.docx (19)

C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Calfem34
Calfem34Calfem34
Calfem34
 
Exploit techniques - a quick review
Exploit techniques - a quick reviewExploit techniques - a quick review
Exploit techniques - a quick review
 
Algorithms devised for a google interview
Algorithms devised for a google interviewAlgorithms devised for a google interview
Algorithms devised for a google interview
 
C language 3
C language 3C language 3
C language 3
 
Function and types
Function  and typesFunction  and types
Function and types
 
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container DayQuantifying Container Runtime Performance: OSCON 2017 Open Container Day
Quantifying Container Runtime Performance: OSCON 2017 Open Container Day
 
SystemVerilog-20041201165354.ppt
SystemVerilog-20041201165354.pptSystemVerilog-20041201165354.ppt
SystemVerilog-20041201165354.ppt
 
There are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdfThere are 37 classes in java.lang package as per Java SE7 The java.pdf
There are 37 classes in java.lang package as per Java SE7 The java.pdf
 
Introduction to apache_cassandra_for_develope
Introduction to apache_cassandra_for_developeIntroduction to apache_cassandra_for_develope
Introduction to apache_cassandra_for_develope
 
OpenMP
OpenMPOpenMP
OpenMP
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
Buffer overflow attack
Buffer overflow attackBuffer overflow attack
Buffer overflow attack
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
Unit 2
Unit 2Unit 2
Unit 2
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...
 
r,rstats,r language,r packages
r,rstats,r language,r packagesr,rstats,r language,r packages
r,rstats,r language,r packages
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

More from rtodd615

Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docxDiscuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docxrtodd615
 
Discuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docxDiscuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docxrtodd615
 
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docxDQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docxrtodd615
 
Discuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docxDiscuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docxrtodd615
 
Does adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docxDoes adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docxrtodd615
 
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docxDiscuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docxrtodd615
 
Distinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docxDistinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docxrtodd615
 
Discussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docxDiscussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docxrtodd615
 
Discuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docxDiscuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docxrtodd615
 
Discuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docxDiscuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docxrtodd615
 
discuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docxdiscuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docxrtodd615
 
Discuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docxDiscuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docxrtodd615
 
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docxDiscuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docxrtodd615
 
Discuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docxDiscuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docxrtodd615
 
Discuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docxDiscuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docxrtodd615
 
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docxDiscuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docxrtodd615
 
Discuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docxDiscuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docxrtodd615
 
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docxdifference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docxrtodd615
 
Effective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docxEffective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docxrtodd615
 
effective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docxeffective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docxrtodd615
 

More from rtodd615 (20)

Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docxDiscuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
Discuss reaction strategies to handle Malware-SolutionMalware- Malware.docx
 
Discuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docxDiscuss the differences between a form and a report- What characterist.docx
Discuss the differences between a form and a report- What characterist.docx
 
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docxDQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
DQuestion 23 10 pts Explain how the de Broglie wavelength is related t.docx
 
Discuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docxDiscuss in scholarly detail implications of any considerations that sh.docx
Discuss in scholarly detail implications of any considerations that sh.docx
 
Does adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docxDoes adding debt increase or decrease the flexibility of a healthcare.docx
Does adding debt increase or decrease the flexibility of a healthcare.docx
 
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docxDiscuss the difference between Financial Accounting and Managerial Acc (1).docx
Discuss the difference between Financial Accounting and Managerial Acc (1).docx
 
Distinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docxDistinguish between individual barriers and organizational barriers to.docx
Distinguish between individual barriers and organizational barriers to.docx
 
Discussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docxDiscussion Topic 1- Internal control consists of the policies and proc.docx
Discussion Topic 1- Internal control consists of the policies and proc.docx
 
Discuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docxDiscuss the tools and technologies for collaboration and teamwork that.docx
Discuss the tools and technologies for collaboration and teamwork that.docx
 
Discuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docxDiscuss the statement of cash flows Values Limitations This relates to.docx
Discuss the statement of cash flows Values Limitations This relates to.docx
 
discuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docxdiscuss the role of nanotechnology in today-'s information age-Solutio.docx
discuss the role of nanotechnology in today-'s information age-Solutio.docx
 
Discuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docxDiscuss the reasons for the growing interest in and availability of hi.docx
Discuss the reasons for the growing interest in and availability of hi.docx
 
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docxDiscuss the nature of Greek theater and the purpose it served in Ancie.docx
Discuss the nature of Greek theater and the purpose it served in Ancie.docx
 
Discuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docxDiscuss the impact of a strong culture on organization and managersSol.docx
Discuss the impact of a strong culture on organization and managersSol.docx
 
Discuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docxDiscuss the advantage and disadvantage of supporting links to files th.docx
Discuss the advantage and disadvantage of supporting links to files th.docx
 
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docxDiscuss how engineers and risk experts view and deal with risks- (Appr.docx
Discuss how engineers and risk experts view and deal with risks- (Appr.docx
 
Discuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docxDiscuss how complementary social- managerial- and organizational asset.docx
Discuss how complementary social- managerial- and organizational asset.docx
 
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docxdifference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
difference between Gre tunnel and vpn tunneling-Solution1- VPN tunneli.docx
 
Effective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docxEffective managers stay abreast of current HR topics- Some relevant is.docx
Effective managers stay abreast of current HR topics- Some relevant is.docx
 
effective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docxeffective managers stay abreast of current HR topics- Some relevant is (1).docx
effective managers stay abreast of current HR topics- Some relevant is (1).docx
 

Recently uploaded

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 

Recently uploaded (20)

internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 

Discuss how to pass the address of an array to a function and provide.docx

  • 1. Discuss how to pass the address of an array to a function and provide an example. Please do not write a complete programming code, only briefly discuss the process and provide a simple example. Solution Passing an array to a funciton is of two types. 1.Passing the array name to the function 2.Passing the address of array name to the function In both the cases, the function takes the address of the first element of array name. Array name itself represents the address of starting element the array. --------------------------------------------------------------------------------------------------------------------- --------- /** Test program to illustrate the passing an array to a funciton. */ #include<iostream> using namespace std; //function header types void printUsingPointer(int *arrPtr,int SIZE); void printUsingArray(int arr[],int SIZE); int main() { //constant size const int SIZE=5; //an array of type integer and stores values int arr[5]={2,3,4,5,6}; /** The function printUsingArray takes the address of the first argument as input argument to the funciton when calling the function */
  • 2. cout<<"Printing array using array notation :"<<endl; //call function printUsingPointer with array,arr and SIZE printUsingArray(arr,SIZE); //create a pointer and assign the address of the starting element of array,arr int *arrPtr=arr; cout<<" Printing array using pointer notation :"<<endl; //call function printUsingPointer with pointer, arrPtr and SIZE printUsingPointer(arrPtr,SIZE); system("pause"); return 0; } /**The function printUsingPointer that takes an array pointer(reference value) and size and print the values using pointer notation where * represents an indirection operator that returns the value at address of arrPtr+index */ void printUsingPointer(int *arrPtr, int size) { for(int index=0;index<size;index++) cout<<*(arrPtr+index)<<" "; } /**The function printUsingArray that takes an array and size and print the values using array notation, arr[index] */ void printUsingArray(int arr[],int size) { for(int index=0;index<size;index++) cout<<arr[index]<<" "; } ------------------------------------------------------------------- sample output: Printing array using array notation : 2 3 4 5 6 Printing array using pointer notation : 2 3 4 5 6