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.
#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;
}
Comments
Leave a comment