All Questions
30,430 questions
1
vote
2
answers
60
views
The passing of 2-dimensional arrays to functions in C by only stating the size of the second dimension
When passing a 2-dimensional array to a function in C, I normally just pass it by using a single pointer.
Example : void process_array(int* arr, int rows, int cols)
I see 2-dimensional arrays also ...
1
vote
1
answer
120
views
Trying to Understand Array Initilization within Struct in C
I am trying to initialize an array which is declared in C struct.
The goal is to use an array and pass it as an argument to a function, which then copies each element of the passed array and assigns ...
3
votes
2
answers
107
views
storing all c stuct arrays in only one single memory segment obtained with malloc/calloc
Suppose I have a database in memory that I want to modify.
Let's say the tables are phone information and items.
The phone information consists of a name up to 99 characters and a character code.
The ...
3
votes
2
answers
201
views
How do we call this "int * name[4]" using this phrase “derived-declarator-type-list array of T"
In C17 we have this(6.7.6.2 #3):
If, in the declaration “T D1”, D1 has one of the forms:
D [ type-qualifier-listopt assignment-expressionopt ]
D [ type-qualifier-listopt assignment-expression ]
D [...
4
votes
2
answers
182
views
Is it acceptable to pass a pointer as an argument for a double pointer in C?
So I've been doing some learning projects in c, and I'm starting to get more comfortable with pointers, however I have come across some phenomena that I can't seem to find much information for.
...
2
votes
3
answers
305
views
Why can we use array of arrays in C?
Why can we use array of arrays in C?
This was my question when I opened C standard language (C17).
I found something interesting (6.2.5 "Types" /20):
Any number of derived types can be ...
0
votes
0
answers
56
views
Can Array be declared with size as function argument, array[variable_size] in C Language (constraint - malloc should not be used) [duplicate]
I need to know if I can have variable as size of array in a loop and in a function.
NOTE: I cannot use malloc.
Using array sizes as shown below, Is it valid? Will it cause any runtime issues / crash / ...
1
vote
1
answer
98
views
"variable-sized object may not be initialized" error message when number of elements are calculated with float
With GCC 11.4 (-std=c99) on Linux WSL, there is an compile error as in example 2) in the code below. I have not gotten this kind of error with other compilers such as TASKING, MULTI, ti-arm-clang.
Do ...
-6
votes
2
answers
257
views
Why does int arr[5] = {1, 2, 3}; set the rest of the array's content to 0?
I declared an array in C like this:
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3};
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return ...
0
votes
2
answers
138
views
Why does this function not modify the original array when passed as a parameter?
#include <stdio.h>
void modifyArray(int arr[]) {
arr = (int[]){6, 7, 8, 9, 10}; // Trying to modify the array
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
modifyArray(arr);
for (...
1
vote
1
answer
93
views
Stuck on a practice problem involving arrays and modifying array of array elements [closed]
There is a problem on Exercism I'm stuck on. I should get the multiples of a factor that are less than the limit and then add them to an array, I should do this to all factors (get their multiples ...
-7
votes
2
answers
196
views
Evaluating ((a + 2) + 3) [closed]
What is the value of * (* (a + 2) + 3)
for this 2D-array? int a[3][3] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
How to solve this?
Is there is a mistake in that question ?
int a[3][3] = {
{1, 2, 3},
{4, ...
6
votes
3
answers
216
views
Why in C can I initialize more values than the size of an array?
This array has a size of 1 but I can initialize it with these values, then I can even set more values after I instantiate the array and it still works. I don't understand why.
int array[1] = {12,2,12,...
2
votes
2
answers
93
views
How change every struct in an array of pointers?
Let's say I have an array of pointers to structs. How do I make it so every element of the array points to a different memory location, so I can change these struct values through pointers ...
2
votes
1
answer
38
views
how can I array the external inputs for code generation in Simulink embedded coder?
I am building the c-code of a Subsystem in Simulink with the embedded coder. The created header file includes the following code-snippet which represents the 6 inports and 2 outports of the subsystem.
...