Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-23-2003, 07:30 PM   #1 (permalink)
mochman
Registered User
 
mochman's Avatar
 
Join Date: Feb 2003
Location: Rochester, NY
Posts: 3
mochman is on a distinguished road
Send a message via AIM to mochman
Passing values by reference

Code:
#include<iostream.h>

// this function will modify the passed in values without having to return anything
void refPassFunc( int &, char &);

int main(void) {
        int userInt;
        char userChar;

        cout << "Please enter a integer : ";
        cin >> userInt;
        cout << "Please enter a character : ";
        cin >> userChar;
        cout << "You have inputted " << userInt << " and " << userChar << endl;
        refPassFunc( userInt, userChar );
        cout << "The new values are " << userInt << " and " << userChar << endl;
        return 0;
}

void refPassFunc( int &intIn, char &charIn ) {
        // will add 6 to the number being passed in
        intIn += 6;
        // will set the character to 'H'
        charIn = 'H';
}
Passing by reference will pass the location of the variable instead of the variable's value. This means that when the function modifes the value of its variable, it is actually modifing the initial passed variable. Phew.
A quick note, all arrays are automatically passed by reference.
mochman is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add an Assembly Reference - Mono twixntwix MS Technologies ( ASP, VB, C#, .NET ) 4 07-08-2004 08:00 AM
passing by reference sde Java 13 05-06-2004 06:22 AM
Java help?? d00ds?? zergmuncher Java 19 11-15-2003 02:35 AM
Passing form data to PHP with Javascript bdl PHP 5 07-03-2002 10:18 AM


All times are GMT -8. The time now is 01:49 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting