Thread: initialization

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    38

    initialization

    sometimes .. we initialize a variable to zero ! why?

    look at this algorithm for example ( nested loop ) :


    Code:
    totalSteps = 0
    FOR outsideCounter = 1 TO 5 INC BY 1
    FOR insideCounter = 1 TO 5 INC BY 1
    totalSteps = totalSteps + 1
    OUTPUT “Outside = “ outsideCounter,
    “ Inside = “, insideCounter,
    “ Total Steps = “, totalSteps
    ENDFOR
    ENDFOR

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by abood1190
    sometimes .. we initialize a variable to zero ! why?
    Because it makes sense.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bad initialization?
    By oklem in forum C Programming
    Replies: 4
    Last Post: 12-18-2011, 10:27 AM
  2. C initialization
    By vpshastry in forum C Programming
    Replies: 10
    Last Post: 09-16-2011, 01:17 PM
  3. assignment vs initialization
    By KIBO in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2010, 09:46 AM
  4. Initialization. Are they the same?
    By lockpatrick in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2002, 11:46 PM
  5. Initialization question
    By cpp4ever in forum C++ Programming
    Replies: 0
    Last Post: 10-19-2001, 05:09 AM