LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-26-2006, 08:52 AM   #1
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445
Blog Entries: 9

Rep: Reputation: 48
array_name[], what does it mean?


When I was looking at the gtkpod/glibpod source code, I noticed a bunch of arrays without a set size. It looked something like
Code:
*array_name[]
I understand that the '*' means its a pointer, that is, it points ot a place in the memory. Why does it not specify the size of the array? I thought arrays were supposed to be used with
Code:
array_name[x]
Is it because it's pointer, that there is no need to set the size?
 
Old 01-26-2006, 09:06 AM   #2
geeman2.0
Member
 
Registered: Feb 2005
Location: Ontario, Canada
Distribution: Gentoo, Slackware
Posts: 345

Rep: Reputation: 30
When you do something like

int array[5];

The [5] tells the compiler to reserve 5 integer sized units of memory.
Since in your example it's a pointer, it's not reserving any memory for the array, it only stores a memory address, so there's no reason to specify an array size, it will just end up pointing to some other existing array in memory.

You can still use the pointer with an array index once it's pointing to an array in memory.
 
Old 01-26-2006, 09:10 AM   #3
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
these are both the same:
*array_name[] = **array_name;

you may have seen it before and not noticed,
int main(int argc, char* argv[])...
int main(int argc, char** argv)...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration