Questions tagged [array]
An array is a systematic arrangement of similar objects, usually in rows and columns.
223 questions
16
votes
10
answers
5k
views
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 ...
0
votes
1
answer
242
views
Elegant way in C to store many parameters with default value and current value in embedded flash
I'm programming an embedded system that has a number of user configurable parameters, which are stored in flash memory. I have to store a default value for each parameter as well as the user settings. ...
27
votes
6
answers
28k
views
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 ...
4
votes
4
answers
1k
views
When should tuples be used as an argument instead of an array?
I hope this isn't too off-topic/opinion-based, I'm new here.
I want to pass three elements of the same type into a function. The three elements are unique cards of a deck of cards, so they're not ...
7
votes
2
answers
4k
views
Why does C not support direct array assignment?
In C you cannot assign arrays directly.
int array[4] = {1, 2, 3, 4};
int array_prime[4] = array; // Error
At first I thought this might because the C facilities were supposed to be implementable with ...
4
votes
2
answers
2k
views
Multidimensional vs nested arrays
A seemingly basic question here.
Is there anything you can do with multidimensional arrays that you can't do with nested arrays?
Many languages have been designed with both facilities and syntactical ...
0
votes
0
answers
166
views
Best choice for a holding large number of objects in java
I have a set of array, containing a large number of objects (products), which has lately grown so large, searching in it takes about a minute, which is considered too long, since one search is ...
2
votes
1
answer
2k
views
Do C++ compilers optimize/pack small data types (e.g. boolean values)?
This occurred to me when looking at stencil computations in numpy. This python library compiles compute-intensive components, so I believe that it's a valid example. Here making selections on an array ...
4
votes
2
answers
1k
views
Arrays vs Maps for listing items that have a unique id
I've been finding that for a lot of code I've been writing recently, it naively might look like this:
Array approach:
const options = [
{
id: 'red',
label: 'Red',
data: '#f00'
...
0
votes
1
answer
136
views
how to store the data for function f(time,length)
I have a function which has discrete time step ,discrete length from origin . These two give height of the function. For example at time 1.2sec , and length 5.5cm from origin height is 10cm. The step ...
8
votes
2
answers
7k
views
Is there a sensible way to sort coordinates?
Sorting is generally used to solve problems where distance between elements matters. A sorted list/array has the convenient property that the smaller the difference between the indices of any two ...
-2
votes
1
answer
129
views
Are jagged arrays lvalue or not?
When I was study lvalue i see that
C expression can be lvalue if a subscript ([]) expression that does not evaluate to an array.
(from
https://docs.microsoft.com/en-us/cpp/c-language/l-value-and-r-...
2
votes
2
answers
764
views
sizeof(a)/sizeof(a[0]) vs sizeof(a)/sizeof(t) where t is type in C from K.N.King
I'm trying to understand why sizeof(a)/sizeof(t) is inferior for getting the length of an array to sizeof(a)/sizeof(a[0]) if just as it's possible to have different types, my elements could also be of ...
1
vote
1
answer
515
views
How should I approach the comparison of two BMP images?
I am currently writing a Python program that retrieves the pixels from two BMP files and finds the percent difference between them (without using the Pillow library for the purpose of learning). I can ...
1
vote
3
answers
556
views
Are 'array elements' and 'array values' the same?
Array := {"title": "Book Title", "author": "John Doe"}
Some people use the following terminology:
title and author are keys.
Book Title and John Doe are values.
"title": "Book Title" and "author": "...
1
vote
1
answer
69
views
Determine array of objects collective identity and be able to inspect it
I have an array of objects and I'm trying to see, through each request, whether or not a new member appeared in my collection.
The way I currently do it is, I require each member of the collection to ...
1
vote
1
answer
677
views
PHP: simple class for storing read-only data structure, array alternative
I need to share some associative data between different parts of my application with two requirements:
immutability (so read-only)
safety against mispelling or unavailable index inside the data
mixed ...
1
vote
0
answers
43
views
is it better to have tracking fields that are maintained separately for arrays? [duplicate]
I wasn't sure exactly how to word this question, but basically, I have a struct stNeuralLayers (for a neural network I'm playing around with) with fields that are matrices (such as a double[,] ...
2
votes
1
answer
2k
views
How should I define hardcoded strings with some variable parts? Reuse more characters? Or keep the whole sentence?
for example, sometimes I need to define a hardcoded string with some variable parts, I often have trouble to choose the style:
style 1 : reuse every characters when possible
showMessage(num){
let ...
0
votes
1
answer
169
views
For arrays, should I use the first position to store the selected element, instead of variable like "selectedIndex", if possible?
For example, I have a toggle button, which would show the current selected element, and would show next element when it is clicked, and it can loop back to first element. I have 2 ways to store the ...
3
votes
2
answers
141
views
Should I move tasks which is just for a specific element only out of for loop?
For example, I have a for loop, which element 0 has additional function to run compared with other elements, my question is, should the additional function be:
1.place inside for loop
for(int i=0;i&...
3
votes
1
answer
159
views
Array rotation algorithm
I'm developing an application which sends quotes to clients via email.
Since quotes are obtained from various resources (per each client) they end up in a single array which is then used as a source ...
1
vote
2
answers
178
views
Linked-list iteration patterns
If you have a linked-list, where the items are not necessarily close to each other in memory, wondering if it is (in general) better/worse/no difference to do the following.
Say you want to iterate ...
4
votes
2
answers
6k
views
How exactly indexing works in arrays?
I only know that index is faster but don't know why is it faster.
Suppose I have an array int[] a = {2,3,6,7}. Then I will try to find the element at a[3] and the speed of this will be O(1). Why? How ...
1
vote
2
answers
665
views
Are there any use cases for List when Deques and Arrays are available?
I've been thinking about this over the past few weeks, and I've come up with no good arguments. My perspective is from Java, but if anyone has any language-specific cases outside of this language, I'...