• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Declaring and initialization of C array.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declaring and initialization of C array.


  • Subject: Re: Declaring and initialization of C array.
  • From: Graham Cox <email@hidden>
  • Date: Thu, 02 Jun 2011 01:17:06 +1000

On 02/06/2011, at 1:12 AM, JAMES ROGERS wrote:

> K&R says to declare and initialize an array in C:
>
> 	int myArray[2] = {1,2};
>
> If the above is entered into the .h file


That's because a .h file is the HEADER.

You need to put this in the BODY, which is the .c (pure C) or .m (Obj-C) file. The reason is that the = {1,2} part is executable code, not just a declaration, so it needs to live somewhere.

--Graham




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Declaring and initialization of C array.
      • From: Ron Hunsinger <email@hidden>
    • Re: Declaring and initialization of C array.
      • From: Wim Lewis <email@hidden>
    • Re: Declaring and initialization of C array.
      • From: John Joyce <email@hidden>
References: 
 >Declaring and initialization of C array. (From: JAMES ROGERS <email@hidden>)

  • Prev by Date: Declaring and initialization of C array.
  • Next by Date: Re: Declaring and initialization of C array.
  • Previous by thread: Declaring and initialization of C array.
  • Next by thread: Re: Declaring and initialization of C array.
  • Index(es):
    • Date
    • Thread