Reinitializing a variable

This is a discussion on Reinitializing a variable within the C Programming forums, part of the General Programming Boards category; I am very new to the C programming language and I am working on a project that involves reinitializing a ...

  1. #1
    Unregistered
    Guest

    Reinitializing a variable

    I am very new to the C programming language and I am working on a project that involves reinitializing a varialbe(s).

    Could someone clue me in how to do this, I am confused

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    You can say, for example:

    i=0;

    anywhere in the program - you just have to declare them at the beginning; the values can (usually) be changed anywhere.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    7
    If you initialize like so:

    int i = 5;

    Then, anywhere that the integer i is in scope, you can change its value:

    i = 2;
    i=0;

    But if you declare the integer as constant:

    const int i = 5;

    The compiler won't let you put another value into this variable.

    i = 8 // compiler will bomb here.

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