An array is a systematic arrangement of similar objects, usually in rows and columns.
Questions tagged [array]
224 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…
Mkkt Bkkt
- 1,271
85
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,701
56
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,523
55
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,193
45
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,907
44
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,267
- 6
- 38
- 70
31
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
- 461
26
votes
6 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
- 393
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
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
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
16
votes
10 answers
C#'s Aversion to Array
I have noticed in documentation, looking at open-source code bases, and just a general sense in the industry that C# developers largely prefer to use List<> or IEnumerable<> over simple array[] types, and I'm wondering if my preference for array…
K0D4
- 423
- 1
- 6
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
15
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
- 261
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,786