An array is a systematic arrangement of similar objects, usually in rows and columns.
Questions tagged [array]
221 questions
112
votes
39 answers
Why are zero-based arrays the norm?
A question asked here reminded me of a discussion I had with a fellow programmer. He argued that zero-based arrays should be replaced with one-based arrays since arrays being zero-based is an implementation detail that originates from the way arrays…

Tamas Czinege
- 1,271
- 3
- 10
- 12
83
votes
3 answers
How do I move away from the “for-loop” school of thought?
This is a rather conceptual question, but I was hoping I could get some good advice on this. A lot of the programming I do is with (NumPy) arrays; I often have to match items in two or more arrays that are of different sizes and the first thing I go…

turnip
- 1,657
- 2
- 15
- 21
54
votes
5 answers
What's the use of .Any() in a C# List<>?
I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#.
You can check the validity of an element in the array like the following statement:
if (MyList.Any()){ ...} //Returns true or…

Gil Sand
- 2,173
- 3
- 18
- 22
52
votes
6 answers
Is initializing a char[] with a string literal bad practice?
I was reading a thread titled "strlen vs sizeof" on CodeGuru, and one of the replies states that "it's anyways [sic] bad practice to initialie [sic] a char array with a string literal."
Is this true, or is that just his (albeit an "elite member")…

Cole Tobin
- 1,440
- 1
- 15
- 28
42
votes
3 answers
How to store ordered information in a Relational Database
I am trying to understand how to properly store ordered information in a relational database.
An example:
Say I have a Playlist, consisting of Songs. Inside my Relational Database, I have a table of Playlists, containing some metadata (name,…

Qqwy
- 4,709
- 4
- 31
- 45
42
votes
2 answers
PHP: when to use arrays, and when to use objects for mostly-data-storing code constructs?
PHP is a mixed paradigm language, allowing to use and return non-object data types, such as arrays. I pose a question to try to clarify some guidelines for selection of arrays vs objects when deciding upon what programming construct to use in a…

Dennis
- 8,157
- 5
- 36
- 68
32
votes
11 answers
How does the "Fourth Dimension" work with arrays?
Abstract:
So, as I understand it (although I have a very limited understanding), there are three dimensions that we (usually) work with physically:
The 1st would be represented by a line.
The 2nd would be represented by a square.
The 3rd would be…

Questionmark
- 471
- 1
- 5
- 9
22
votes
3 answers
Should I use a list or an array?
I'm working on a windows form to calculate UPC for item numbers.
I successfully create one that will handle one item number/UPC at a time, now I want to expand and do it for multiple item numbers/UPCs.
I have started and tried using a list, but I…

campagnolo_1
- 331
- 1
- 2
- 6
20
votes
3 answers
Professional way to produce a large problem without filling up huge arrays: C++, free memory from part of an array
I'm developing a physics simulation, and as I'm rather new to programming, I keep running into problems when producing large programs (memory issues mainly). I know about dynamic memory allocation and deletion (new / delete, etc), but I need a…

Drummermean
- 327
- 2
- 7
18
votes
5 answers
How can Rust be "safer" and "faster" than C++ at the same time?
I have been told that Rust is both safer and faster than C++. If that is true, how can that be even possible? I mean, a safer language means that more code is written inside the compiler, right? More code means more instructions for the processor to…

euraad
- 305
- 2
- 6
17
votes
4 answers
size_t or int for dimensions, index, etc
In C++, size_t (or, more correctly T::size_type which is "usually" size_t; i.e., a unsigned type) is used as the return value for size(), the argument to operator[], etc. (see std::vector, et. al.)
On the other hand, .NET languages use int (and,…

Ðаn
- 584
- 1
- 5
- 16
15
votes
1 answer
Why prefer sizeof(element) over sizeof(TYPE) for calculating the number of elements in an array?
I'm reading "King K.N's C programming" and found the following statement:
We discussed using the expression sizeof(a)/sizeof(a[0]) to calculate the number of elements in an array. The expression sizeof(a)/sizeof(t), where t is the type of a's…

Higgs
- 169
- 6
14
votes
6 answers
Why can't C arrays have 0 length?
The C11 standard says the arrays, both sized and variable length "shall have a value greater than zero." What is the justification for not allowing a length of 0?
Especially for variable length arrays it makes perfect sense to have a size of zero…

Kevin Cox
- 251
- 2
- 5
13
votes
8 answers
What is the difference between an Array and a Stack?
According to Wikipedia, a stack:
is a last in, first out (LIFO) abstract data type and linear data structure.
While an array:
is a data structure consisting of a collection of elements (values or variables), each identified by at least one array…

Dynamic
- 5,746
- 9
- 45
- 73
11
votes
2 answers
How did the custom of using square brackets for array elements develop?
Many programming language use the syntax a[i] to refer to the i'th element of an array, sequence, or vector a - specifically, C and Pascal (from the late 1960s and early 1970s) do this. On the other hand, some earlier languages, like that Fortran…

einpoklum
- 2,478
- 1
- 13
- 30