Questions tagged [pointer-to-pointer]

Pointers are variables themselves, so a pointer that points to another pointer is a pointer to pointer. A pointer to pointer is sometimes mistakenly referred to as "double pointer".

234 questions
1
vote
0 answers

Setting the values of pointers inside another function

I am having some trouble with pointers in C. Basically, we are tasked with programming an N-ary tree (family tree). Any single node can have any number of children (0, 1, 2, ...). I am stuck at the part of adding a single parent and a single…
Some Guy
  • 351
  • 1
  • 4
  • 20
1
vote
1 answer

Accessing pointer to pointer of struct using -> operator

I have this code: #include #include struct node { int data; struct node *next; }; void pointerOfPointer(struct node **reference) { struct node *temporary = malloc(sizeof(struct node)); temporary->data = 100; …
adipginting
  • 77
  • 1
  • 10
1
vote
2 answers

memset operation on double pointer

Question is relevant. For the below representation, typedef struct List{ void **array; // array of void* int lastItemPosition; int size; }List; #define INITIAL_LIST_SIZE 50 createList performs as shown below, List…
overexchange
  • 15,768
  • 30
  • 152
  • 347
1
vote
4 answers

Assign null to the address of a pointer

How can I deinitialize x inside the free_x function? I have to do it in order to fit to an API method. I can very easily deinitialize x just by assigning null to it but I have to do it inside the free_x function. typedef struct { int field1; …
sanchop22
  • 2,729
  • 12
  • 43
  • 66
1
vote
1 answer

Is it correct to declare a dynamic array of atomic using double pointers in C++?

I need to create an array of atomic integers i.e. n integers each of which are atomic. I found that std::vector> will not work but then I tried the following approach and it compiles successfully with clang. int n; std::cin >>…
1
vote
3 answers

Copying a pointer of a pointer (matrix) values in C

The problem is the following: I created a dynamic matrix, using pointer to pointer matrix1 I want to create a copy of this matrix into another, matrix2 I want to do that so I can mess with matrix2 without messing with matrix1 So I tried to do the…
Hirosam
  • 13
  • 1
  • 7
1
vote
3 answers

Use of ptr-to-ptr array?

What is the use and explanation of something like this?: int capacity; int** number; this->number = new int*[this->capacity]; I'm studying for an exam and in a test exam they put the requirement of using a pointer-to-pointer object and making a…
Jack Of Blades
  • 495
  • 7
  • 16
1
vote
0 answers

Pointer to pointer usage in swap linkedlist node

I met this problem of swapping consecutive two nodes from beginning to end of a linked list.(Eg. [1,2,3,4] to [2,1,4,3] or [1,2,3,4,5] to [2,1,4,3,5]) I found the pointer to pointer solution hard to understand. Can anyone help me on the following…
YYX
  • 11
  • 1
1
vote
3 answers

Pointer arithmetic is working but pointer de-referencing is not working

I am trying to use pointer arithmetic to access pointer locations like an array. For testing same I wrote below code. Now, I can see that pointer arithmetic is working because I can see incremented pointer address getting printed. But when I am…
hagrawal7777
  • 14,103
  • 5
  • 40
  • 70
1
vote
1 answer

Memoryleak with pointer to pointer, C++

I'm trying to do a Phonehandler system for a class I'm taking, The task specifies that we use a pointer to pointer for the Phone objects in the Phonehandler-class, and that the array to store Phones has a size of two phones from the start and that…
Adam
  • 11
  • 2
1
vote
3 answers

What exactly int/char when we declare double pointer(**q)

Lets take 64 bit machine where pointer is of 8 bytes in 64 bit machine int *p ; // it is a pointer to integer variable so when i increment p // i.e., p++ it will increment by 4 char *r; // It is pointer to character . // So if…
Vivek
  • 181
  • 3
  • 10
1
vote
3 answers

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 the addresses. I have a function to get data from…
Nonemoticoner
  • 650
  • 5
  • 14
1
vote
2 answers

Strcmp causes segfault

Here is the code: #include #include #include int my_compare(const void * a, const void * b); int main() { char s[][80] = { "gxydyv", "gdyvjv", "lfdtvr", "ayfdbk", "sqkpge", "axkoev", "wdjitd", "pyrefu",…
nalzok
  • 14,965
  • 21
  • 72
  • 139
1
vote
6 answers

how to use a pointer to pointer to insert in a linked list

Think is a function to insert new element in the order of name. I knew how to do it if I use a if to separate condition of inserting at the start and others. But I was asked to merge the if and while into a single while loop. How could i integrate…
NUO
  • 247
  • 2
  • 3
  • 14
1
vote
2 answers

What value does a pointer to pointer get assigned when points to a dynamically allocated memory?

Consider the following case: int **my_array = new int*[10]; What do we assign to my_array here? my_array is a pointer that points to what? Is there any way to iterate through my_array (the pointer) and set up a two-dimensional array of integers…