250 questions
Advice
0 votes
3 replies
96 views
Restrict keyword and pointers to pointers
I'm in C and I have an int ** (2 dimensional array, it's basically a matrix, it's actually set up a little bit complicated but there's no internal aliasing, so it's not relevant). is this int** ...
0 votes
3 answers
216 views
Realloc in function that deletes a row in a matrix
I have just encountered a case in this C program: void row_del(int**& a, int& row, int col, int k) { for (int j = 0; j < col; j++) { for (int i = k; i < row - 1; i++) { ...
3 votes
4 answers
150 views
What's wrong with this code, which gets content (chars) from file and stores it in char**?
I have a small project (ed-like text editor for myself. Just want to edit some config files using it) and I have some problems with it. workspace_file->flc = malloc(sizeof(char *)); ...
1 vote
3 answers
235 views
Deleting one node of single linked list use double pointers in C language
I have been reading something related to C language's double pointers, and I have some doubts about the following piece of code. The following piece of code is about the operation of deleting a node ...
0 votes
3 answers
131 views
Accessing information on a 2d array with a double pointer in a struct (C)
In trying to understand pointers, I created a M[x][y] array, a pointer to said array *p_M[x] and a pointer to said pointer **d_p_M. The first pointer points to the first element of a row in the array ...
2 votes
3 answers
164 views
Converting to char*** from char* [2][2]
I have the following variable char* a[2][2] = {{"123", "456"}, {"234", "567"}}; I wanted to refer it using another variable. While the cast works, accessing ...
0 votes
0 answers
65 views
Why do we use a single pointer rather than a double pointer to pass an array to a function? [duplicate]
Why not double pointer to take an array? I'm having a bit of problem understanding why an array isn't passed as a double pointer (a pointer to a pointer) since the array name itself is a pointer (...
0 votes
4 answers
119 views
char * gives garbage value when pointing to a variable of a function in C
When i pass a pointer to a function and then change the pointer to a another location of the memory, I get SIGSEV or garbage values. Where is a code to demonstrate that: #include <stdio.h> void ...
2 votes
2 answers
133 views
why do I need to add an & sign while allocating a memory space inside a functions? [duplicate]
I wanted to try making an allocate function for a cell in a list, but when using it inside another functions, I need to add an "&" sign I am aware of what "&" means in c (...
0 votes
2 answers
87 views
"Magically" avoiding segfault
I wrote a small demo program #include <stdlib.h> #include <stdio.h> typedef struct tag_node { struct tag_node *left, *right, *prev; int value; } node; int main() { node *...
1 vote
0 answers
82 views
Marshalling double pointers in C#
I have to interact with a provided C library where one of the functions is declared as follows: int GetFileList(struct spiflash_file **ptr_spiflash_filelist, int **file_num); where **...
1 vote
2 answers
72 views
Using realloc with pointer to pointer in another function
I'm trying to use realloc in this program to increase an array's size, using pointer to pointer. But it doesn't end up doing the task: #include <stdio.h> void push(int** data) { *data = (...
1 vote
1 answer
258 views
Runtime error: `load of null pointer of type 'char'` when indexing an array
I'm trying to write a trim function, but when I try to use it the compiler is giving me a runtime error or load of null pointer of type 'char' when I try to run this code: // Trim trailing whitespace ...
2 votes
1 answer
126 views
Necessity of double pointer when using realloc to manipulate array
I am new to C++ programming and want to try out manual memory management (I am aware that it is advised not to use manual memory management, but I still want to give it a try). My goal was to write a ...
-3 votes
2 answers
129 views
Confusion about C pointers
I am sending this message to clear my confusion that I could not manage and handle. The foo1 function code should work. I am giving the code details for you. When I run the code, the result is a ...