All Questions
10,982 questions
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.
...
1
vote
5
answers
217
views
How does array indexing work differently between 1D and 2D arrays in C++?
I'm confused about how array indexing actually works in C++. I understand that when we use the expression x[n] (where x is an address and n is an integer), the compiler treats [] as an operator that ...
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 (...
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 ...
3
votes
1
answer
106
views
Using array as smart point in C
In C++, you can use smart pointer to ensure no memory leak.
But in C, it doesn't support OOP (since smart pointer is based on OOP), does it make sense to use an array to act like a smart pointer, and ...
0
votes
1
answer
69
views
How to use ref mut for an array?
Are these lines equivalent?
let ref mut a : [i32; 100]= [10;100];
let ref mut a : &mut[i32; 100]= &mut[10;100];
If yes why? And if no, what does it change?
1
vote
1
answer
80
views
Getting address of one struct within an array in C
I have an array of structures.
typedef struct { int a; int b; } s;
static const s info[2] = {
{.a=1, .b=2}, {.a=3, .b=4 }};
I also have a pointer to this kind of struct:
static s *thisInfo;
I want ...
0
votes
3
answers
127
views
Use of const keyword with array pointers in C
In the 9th edition of Deitel's book C. How to program (chap. 7), a function is declared as
void bubbleSort(int * const array, size_t size)
and in the text it's specified that "function ...
1
vote
1
answer
63
views
The error is: passing argument 5 of 'init_node' from incompatible pointer type [-Wincompatible-pointer-types]
char initial_req_item[MAX_ANSWER_COUNT][10] = {" ", "свиня", "меч"};
int initial_req_val[MAX_ANSWER_COUNT] = {0, 1, 1};
int is_initial_req[MAX_ANSWER_COUNT] = {0, ...
0
votes
3
answers
117
views
Why is the '&' operator needed for an int variable but not for an array in C? [duplicate]
#include <stdio.h>
#include <stdlib.h>
int main(){
char name[100];
int age;
printf("Enter you name:\n");
scanf("%s", name);
printf("Enter you ...
0
votes
1
answer
55
views
Function with a malloc on a pointer declared in main()
I looked at many similar questions on this subject, but most seem to focus on a pointer being passed to a function as parameter instead of the pointer's address so haven't found my answer.
A segfault ...
0
votes
2
answers
87
views
Can't access data in array after using realloc in other function
During class i had to write simple program that uses array of structs, said program needs to add elements and display one or all elements. Teacher said that we can't use vector and that we must use ...
-2
votes
4
answers
175
views
How does a pointer to a whole array work in C++? [duplicate]
In C++, there is a concept of a pointer to an array, where it is said to point to the "whole array" rather than just the first element. This idea confuses me. How can a pointer point to an ...
2
votes
2
answers
68
views
Segmentation Fault / Memory Access Violation when accessing array of array (doublepointer)
This is my code.
I'm allocating memory to a dynamic array and trying to print it with fn().
I won't be able to pass the array normally (like int *v) I can only pass it as int **v for specific reasons.
...