Roberto Dias wrote:
What about to interchange variables between functions? Which are the
best way to do this? I know that this is a fundamental question, but I
C++ fundamental student yet. I just started few day ago on studying
about functions and I'm so excited to implement some ideias about text
files processing.
thanks,
Roberto Dias
There are two methods: Pass pointers to the variables or
have the function require references.
#include <iostream>
#include <cstdlib>
using namespace std;
void Add_Five(unsigned int& num)
{
num += 5;
return;
}
void Add_Ten(unsigned int * p_num)
{
*p_num += 10;
return;
}
int main(void)
{
unsigned int orig_num = 2;
cout << "Original number: " << orig_num << endl;
Add_Five(orig_num);
cout << "After call to Add_Five: "
<< orig_num << endl;
Add_Ten(&orig_num);
cout << "After call to Add_Ten: "
<< orig_num << endl;
return EXIT_SUCCESS;
}
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book