473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Interchanging variables between functions

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
Jul 22 '05 #1
1 1290
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

Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Angelos | last post by:
hello there... I would like to ask if there is any way of using variables which are outside functions in the functions without passing them when I call the function... Complicated eehh ? I have...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
7
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a...
3
by: darrel | last post by:
This is something I should know, but I don't. Say I have this: Function dim variable1 dim variable2 do stuff with the variables
9
by: Pohihihi | last post by:
What could be the possible reasons (technical/non technical) of not using lots of static functions or variables in a program keeping in mind that Framework by itself has tons of static functions and...
9
by: CDMAPoster | last post by:
About a year ago there was a thread about the use of global variables in A97: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157 Best Practices by Kang...
1
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
1
by: Tarik Monem | last post by:
Hi guys, As usual, I've found some code from the net, changed it around, added some things and it works, but not exactly the way that I'd like it to work. I want it to work like the app on...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.