In: Computer Science
Write a program that contains the following
void increment (int *a, int b); //do NOT define this function // this function adds b to the value pointed to by the first argument
Answer1:
#include <iostream>
using namespace std;
int * copies(int n,int x){
int *p=new int[n];
for(int i=0;i<n;i++)
*(p+i)=x;
return p;
}
int main(){
int *arr=copies(5,-1);
for(int i=0;i<5;i++)
cout<<arr[i]<<" ";
delete arr;
}
Answer 2:
#include <iostream>
using namespace std;
void increment (int *a, int b){
(*a)=(*a)+b;
}
int main(){
int y=10,z=3;
cout<<"y = "<<y<<endl;
increment(&y,z);
cout<<"y = "<<y<<endl;
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME