Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 6th, 2006, 05:49 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to random_eh
Default Help a student re: Re-using variables

In main I use a variable say "char user_input;" then I no longer have a need for that particular variable. However, I do need another variable say "char function_result;"

The way I see it I can easily do two things:
 1) make a new variable
 2) or use the old variable
but is there a way to rename the old variable with the new name?
Reply With Quote
  #2 (permalink)  
Old February 7th, 2006, 12:54 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope. Make a new one -- it's stylistically more pleasing for a tiny (and temporary) impact on memory consumption.

----
Scott J. Kleper
Author, "Professional C++"
(Wrox, 2005)
Reply With Quote
  #3 (permalink)  
Old February 7th, 2006, 04:57 PM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to mikhailberis
Default

There is a way, but it might be clumsy.

You can do something like this:

...
char my_first_char;
// do other things
// then use the old variable
// to use the space of the old variable
char & another_char(my_first_char);

Dean Michael C. Berris
Orange and Bronze Technologies, Inc.
Mobile +639287291459
Reply With Quote
  #4 (permalink)  
Old February 27th, 2006, 08:47 AM
Authorized User
 
Join Date: Nov 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Its not renaming...it's giving another name. :)

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Student login form aaronjaf Access 1 May 8th, 2006 03:29 AM
*student* in need of help satinder Access 2 April 4th, 2005 06:32 AM
* student * in need of help satinder Classic ASP Databases 1 April 2nd, 2005 08:34 AM
Student Version stu9820 Dreamweaver (all versions) 3 September 7th, 2004 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.