All Questions
Tagged with pointer-to-pointer function
14 questions
0
votes
0
answers
63
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 (...
2
votes
1
answer
109
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
122
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 ...
1
vote
3
answers
63
views
How does this code allocate memory and why does it fail to write to the allocated memory?
Why does the code below compile successfully but fail to write memory other than address 0? (compiled in dev-cpp 6.3)
#include <stdio.h>
#include <stdlib.h>
void alloc_arr(int **d_ptr);
...
-1
votes
1
answer
77
views
Passing a pointer from one function to another
I am working in C. I have updated the code to include changes made after reviewing comments/suggestions so far.
#include<stdio.M>
#include<math.M>
float * fun2(float Z1, float Z2, float ...
-1
votes
1
answer
38
views
Why is a pointer to a structure not overridable in a function? [duplicate]
lets look at this code:
typedef struct nodes{
int val;
struct nodes next;
} node;
insertHead(node *list, int val) {
node *temp = malloc(sizeof(node));
temp->val;
temp->next =...
0
votes
1
answer
100
views
Double pointer with array in another function
I have to create a program that has an array of costumers (structs that contain name, code and documentation) and functions to insert, remove and list all of them in order of code. I'm not ...
1
vote
0
answers
839
views
Passing 2D Integer Array as double-pointer to a function VS 2D String Array as double-pointer doesn't behave the same? [duplicate]
Hi I am trying to understand the difference between passing a 2d array of type char VS type int to a function as a double-pointer func(int **ptr) parameter. The problem is that it behaves differently. ...
2
votes
2
answers
74
views
Do I need a pointer to a pointer here?
I have the following code:
char* get_line(char *buffer, char *line, char *partialLine) {
int i = 0;
while (buffer[i] != '\n' && buffer[i] != '\0') i++;
if (buffer[i] == '\n') {
...
1
vote
3
answers
77
views
Add data dynamically to array of pointers to structures within function
I tried many combinations but really nothing worked. It's been long enough so I decided to write this issue.
I just want an array of pointers to structures so I could later easiely sort it by swaping ...
0
votes
1
answer
74
views
Is there mechanism for constant pointer to pointer in C?
I wonder does C/C++ allow one to use "const int **" in function call?
Suppose I have a matrix, which can be accessed by pointer to pointer. When I want to use this matrix, and forbid modification of ...
1
vote
5
answers
2k
views
I thought double pointers were required when wanting to change values
When researching double pointers, the general consensus appears to be when wanting to change the value of any variable and retain the new value when returning from a function then its pointer value ...
0
votes
2
answers
80
views
When I try to run it the program crashes and I don't know why
I want to return in my function the n - size of the matrix - and the matrix itself at *p.
The file is something like, for example,
3
10
20
30
this is how I call it:
main( )
{
...
2
votes
5
answers
1k
views
Pass multiple-dimensional array to a function in C
I have a function like this:
void myfunc(int** arr, int n) {
int i, j;
for(i=0; i<n; ++i) {
for(j=0; j<n; ++j) {
printf("%d,", *(arr + i*n + j) ); // Print numbers with commas
...