Thread: reiinitialsing a variable

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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, 12:07 PM
  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, 04:11 AM