Thread: Which is better?

  1. #1
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124

    Which is better?

    Two quick questions..

    1) Is it possible to put a blank space in a int array? I have zero's in there presently but was wondering if I could put blank spaces in it like you can in a char array.

    2) Which is better?


    Code:
    // horizontal 
       if ( (x1 == 1) && (x2 == 1) && (x3 == 1) )
          return 1;
       else if ( (x1 == 2) && (x2 == 2) && (x3 == 2) )
          return 2;
       
       if ( (x4 == 1) && (x5 == 1) && (x6 == 1) )
          return 1;
       else if ( (x4 == 2) && (x5 == 2) && (x6 == 2) )    
          return 2;
    ...
    or

    Code:
    // horizontal 
       if ( (x1 == 1) && (x2 == 1) && (x3 == 1) )
          return 1;
       else if ( (x1 == 2) && (x2 == 2) && (x3 == 2) )
          return 2;
       else if ( (x4 == 1) && (x5 == 1) && (x6 == 1) )
          return 1;
       else if ( (x4 == 2) && (x5 == 2) && (x6 == 2) )    
          return 2; 
    ...
    There are quite a few more if statements. Thanks for your time

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    1) You can put the numeric value of a black space, although I don't see how that'll be useful because you'll have some number, it's probably better just to leave it to zero.

    2) I'd say the first one, because it groups together the related checks and there's a clear distinction between them.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I'd have to agree that the first one would be better.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Is it possible to put a blank space in a int array?
    No. Every memory location in your computer contains some numerical value. ..."How many eggs are in the basket?" You can answer zero, but you can't answer "blank".

    A blank space in a character array has a decimal value of 32 (decimal), which is the ASCII code for a space.

Popular pages Recent additions subscribe to a feed