Thread: Initalizing nothing for ints

  1. #1
    Steph
    Guest

    Talking Initalizing nothing for ints

    Can anyone tell me if it is possible to initalize an array of integers as nothing. I have tried the following:

    int NumArray[]={' ',' ',' ',' ',' '};

    The complier allows me to do this, but when debugging a strange number appears in the array. Can anyone help please.

    Thanks, in advance.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    26
    int numarray[] = {0, 0, 0, 0};

    the way you have it your storing the int value for a space.

  3. #3
    Steph
    Guest
    The code that I am using must not have zero or any other number until a certain point. There bust be a way that u can store a blank space in an int. like char a = ' ';

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    26
    The code that I am using must not have zero or any other number until a certain point
    Why?
    The integer value for a space is 32 so you can't use that, the only other thing I can think of is to use '\0' or NULL. But that is using a zero really.
    int numarray[] = {'\0', '\0'};
    int numarray[] = {NULL, NULL};
    Last edited by Edge; 01-20-2002 at 04:00 PM.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by Edge
    int numarray[] = {0, 0, 0, 0};

    the way you have it your storing the int value for a space.
    An easier way;

    Code:
    int NumArray[10] = {0};
    This fills all members with 0.

    And Edge is right, why do you want a space in an integer array? It makes no sense.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    32
    When you create a variable it will always have a memory address allocated for it, even if you don't initialize it. The contents of that variable will in that case be unpredictable i.e. garbage. I don't think you can have a variable without a memory address, and there will always be some value at that address.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. initalizing arrays
    By spaghettihoop5 in forum C++ Programming
    Replies: 2
    Last Post: 07-02-2006, 03:01 PM
  2. Initalizing global variables to constants
    By maxhavoc in forum C Programming
    Replies: 6
    Last Post: 06-21-2006, 11:25 AM