I have never seen this

Discussion in 'iPhone/iPad Programming' started by nashyo, Aug 19, 2012.

  1. macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    I have been using Objective C to make Apps for 8 months now, and I have never seen this before.

    What's going on here?

    int version[] = {0};
     
  2. macrumors member

    SteppingStone

    Joined:
    Aug 6, 2012
    #2
    This is a plain C array initialization. For some reason the author is initializing a one-element array of int. The syntax is a little more obvious when initializing an array with more than one element, e.g.

    Code:
    int myThreeElementArray[3] = {1,2,3};
    
    will initialize an array of 3 ints with values 1,2,3. Since the right-hand-side contains explicit values, you could also omit the size and get the same result with

    Code:
    int myThreeElementArray[] = {1,2,3};
    
    On the other hand, if you omit the explicit initializer, you'd have to specify the size.
     
  3. thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #3
    thanks
     

Share This Page