Answer to Question #259359 in C++ for james

Question #259359

Write a C++ program to create two pointers of integer type, now take values in these pointers and pass them to a function.Function will update both the values by adding “1” to them. Display the updated values in main.



1
Expert's answer
2021-10-31T12:02:05-0400
#include<iostream>
using namespace std;
void func(int& a, int& b)
{
	a++;	b++;
}
int main()
{	
   int val1=1;
   int* pval1=&val1;
   int val2=3;	
   int* pval2=&val2;
   cout<<"Primary values:\n";
   cout<<"pval1= "<<*pval1	
       <<"\npval2= "<<*pval2;
	func(*pval1,*pval2);
	cout<<"\nFinish values:"; 
   cout<<"\npval1= "<<*pval1	     
       <<"\npval2= "<<*pval2;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS