reiinitialsing a variable

This is a discussion on reiinitialsing a variable within the C++ Programming forums, part of the General Programming Boards category; hi can anyone help me here; i have a while loop that carries out some operations on an array ive ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    reiinitialsing a variable

    hi can anyone help me here;

    i have a while loop that carries out some operations on an array ive named arrayQ - at the end of the loop i want to reinitialise arrayQ back to its original value which i have stored in an array called array_Qcopy.

    for some reason the code below doesnt work, on the first loop through the while statement - the original value changes to the modified one - instead of the modified one changing back to the original.

    Code:
    for( k = 0; k < size; k++)		
    {array_Q[k] = array_Qcopy[k]; }
    please help !!!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Without seeing how you declared (and used) these arrays prior to this, it's hard to say whether you're doing the right thing or not.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    You should also probably perform your operations on the copy, rather than the original. std::vector might be a better choice though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  2. static class variable vs. global variable
    By nadamson6 in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2005, 03:31 PM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21