Hi everyone.
So here's the case, I am a newcomer in C++ and I have been working on a small begginers program ; it adds 2 numbers after adding 1 to each of those 2 numbers . Let's say if we put 4,5 then it will add 1 to both of them (5,6) and the result after adding them both will be 11 of course.
Here's the program that I have made for this using pointers:
#include <iostream.h>
int sum(int *a, int *b);
main()
{ int x,y,z;
x=12;
y=8;
z=sum (&x,&y);
cout<<"sum("<<x<<","<<y<<")="<<z;
return(0); }
int sum( int *a, int *b)
{ *a=*a+1;
*b = *b+1;
return (*a+*b); }
The first thing, I wanna make sure that this program is right and it's the way to do the request in pointers. I think it's the right way cuz I tested it and run it without getting any errors.
The second thing is that I wanna know how I can make this program work without getting the pointers to do the return method. I mean doing the request directly without needing to put the return line.
I think I should make a third pointer and also add it in the line:
z=sum(&x,&y);
But what else then should I do? Should I erase the last 3 code lines and add it to the main class?
Waiting for your anyone's help.