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
0
votes
1 answer

parse line from file to list in c c90

I'm working with c90 on linux. I have a strange bug when I want to end a string, let idx be the index, so when I get to the last index I want the list[idx] to be NULL. example: list[0] actually "hello" list[1] actually "world\n" list[2] sometimes is…
Ruslan Ver
  • 127
  • 4
  • 12
0
votes
1 answer

segfault when setting character of malloced pointer-to-pointer string

In a bigger project i have been working on, i got an Segmentation fault (core dumped), so i managed to reproduce the problem like this: #include #include #include int main() { char **x = malloc(10 * 10); …
0
votes
2 answers

why can't i use casting to deal with pointer to pointer variable without using double asterisks? - This is purely academic

I was just trying something to understand pointer to pointer deeply. I write the code below int x = 20; int *p0 = &x; int *p1 = &p0; printf("*p0 = %d\n", *p0); printf("**p1 = %d\n", *((int *)*p1)); I thought the output would be *p0 = 20 **p1 =…
0
votes
1 answer

Deleting head node of a linked list in C where every node knows its headlist

typedef struct node { int x; struct node *next; struct node **head; } node; Considering this struct, I've implemented a push function: node *push(node *nodo, node *top) { nodo->next = top; top = nodo; nodo->head = ⊤ …
0
votes
1 answer

Searching for a string in BST fails

I am searching a string in a BST. If I found the string, I just return it. If not found, I print 3 suggestions: the last traversed node before declaring that the node is not found the inorder successsor the inorder predecessor My code: #include…
0
votes
1 answer

I am trying to load words from a text file into a binary search tree

I am trying to load words from a text file into a binary search tree. Each line of the file contains one word. #include #include #include typedef struct node node; struct node { node *left, *right; char…
0
votes
0 answers

Why dereferenced pointer to pointer is not the same as pointer?

I recently wrote a MyStack class which would work just like STL stack. Now i decided to write MyStack struct, which I will work with using functions instead of methods struct Stack { int _data; Stack* _next; }*stack; I have Erase function…
Miroigrin
  • 11
  • 1
0
votes
1 answer

Getting "corrupted size vs. prev_size" in C++

I'm trying to create a program to print a 2D matrix after reading in data from a file. My program works fine if the 2D matrix is a square with equal X & Y values, but I get the "corrupted size vs. prev_size" error if its a rectangle, for example…
0
votes
2 answers

Why is a double-void pointer required here? Dynamic "generic" array

I tried to implement a form of collections-library. I do it all the time, when learning a new language, because it teaches most of the language details. So, I started with a form of "generic" dynamic array. Well it is not really generic, because it…
456c526f
  • 123
  • 6
0
votes
3 answers

dereferencing pointer to a pointer with one Asterisk

#include int main(){ int integer = 300; int* p = &integer; int** pp = &p; printf("*pp = %i", *pp); } My question is what is actually *pp? What does it mean to print the value in the address of *p ?
Sayem Rahman
  • 91
  • 1
  • 10
0
votes
3 answers

print each char of string array with double pointer in C++

The program is expected to print each char of the string array. #include #include using namespace std; int main() { const char* numbers[10]{"One", "Too", "Three", "Four", "Five", "Six", "Seven", "Eight",…
Yifangt
  • 151
  • 1
  • 10
0
votes
2 answers

Pointer to pointer in c source file

I see a code which says the following. typedef struct dummy { int a; int b[100]; } dummy_t; typedef struct dummya { int a; int b; } dummya_t; void * getptr(){ // return a pointer of a memory } void function(){ …
Peace9795
  • 11
  • 6
0
votes
4 answers

How is &head of type pointer to pointer?

assuming we have a pointer called struct node *head When referring to this as &head the type becomes pointer to pointer (struct node**) why is this?
programmer
  • 669
  • 3
  • 11
0
votes
0 answers

Matrix transposed with pointer-to-pointer in c++

I am trying to transpose a matrix with pointer-to-pointer in c++ but there is an error: "segmentation fault ('core' dumped)". I tried to find the error on forums and figured out that in matrixTrans function, the 'puntero_trans = new int *[nCol];'…
RT -Jeo-
  • 61
  • 2
  • 3
0
votes
2 answers

Why pointer to pointer was used in the code?

Why pointer to pointer has been used rather than single pointer in the code? Also do you think the destructor was written wrong if it is how can i make it correct? pointer to pointer: employee** _arr; You can see the code…