Questions tagged [double-pointer]

The term "double pointer" is sometimes confusingly used to refer a data type which can point to another pointer. This name is confusing because it may mean a pointer to a `double` floating-point object. Please use [pointer-to-pointer] instead.

The term "double pointer" is sometimes confusingly used to refer a data type which can point to another pointer. This name is confusing because it may mean a pointer to a double floating-point object. Please use instead.

337 questions
4
votes
1 answer

Accessing structure elements via double pointers in C

I'm implementing linked lists using structures. I have a structure - typedef struct llist node; typedef node *nodeptr; struct llist { int data; nodeptr next; }; Now lets say I declare a variable nodeptr *ptr;. How do I access the members…
nsane
  • 1,715
  • 4
  • 21
  • 31
4
votes
2 answers

Double pointers to add an element to a linked list

So I'm trying to add a card to a player's hand... and the value of the card will only be passed back to the main function if I use a double pointer for the top and last cards. But last->pt can't translate to temp, how do I fix this? typedef struct…
3
votes
2 answers

Passing by reference of a pointer to a const object

I've been working on a project that using good amount of double pointers and I was finding I was getting some bugs with it. After spending some time digging into it I've realised the issue is when you pass a non-const object via a reference of a…
Joshua Williams
  • 155
  • 1
  • 7
3
votes
2 answers

Arithmetic of the double pointers with a data structure

i tryied to write the hashtable and found this github repository: enter link description here. I'm having difficulty understanding this code: struct entry_s { char* key; char* value; struct entry_s* next; }; typedef struct entry_s…
Hasbridge
  • 173
  • 1
  • 5
  • 14
3
votes
1 answer

Why does using a char** cause a segfault where a char* works?

Part 1 int main(int argc, char **argv) { int fd; int i; char *line; if (!(fd = open(argv[1], O_RDWR | O_CREAT))) { printf("Error in open\n"); return (0); } while ((i =…
3
votes
2 answers

Confused with the usage of double pointers insertion of nodes in a Binary Tree

So here is the function that works fine: void Insert(node ** root, int inpdata){//tree's root should be passed here if(*root == NULL){ *root = createNode(inpdata); } else if(inpdata < (*root)->data){ …
Huzo
  • 1,652
  • 1
  • 21
  • 52
3
votes
3 answers

Best way to allocate memory to a two-dimensional array in C?

What is the best way to allocate memory to a two-d array in C,from both the perspectives : memory-management and speed ? Also, which is better to use, a two-d array (and allocate memory to it) or a double pointer ? Can someone explain in…
Jarvis
  • 8,494
  • 3
  • 27
  • 58
3
votes
2 answers

Why this code is giving compilation error?

I am trying to learn about double pointers.I am trying to print a 2d array by passing the address of the array to a function.But compilation error is coming.I am unable to understand why ?? Below is the…
asad_hussain
  • 1,959
  • 1
  • 17
  • 27
3
votes
2 answers

segmentation fault with uint8_t double pointer

I have a segmentation fault when affecting a value to a[1][0], i thought my mallocs were correct but maybe there're not.. int main() { uint8_t **a; a = malloc(sizeof(uint8_t) * 6); *a = malloc(sizeof(uint8_t) * 2); a[0][0] = 1; //…
aurel_lab
  • 149
  • 11
3
votes
5 answers

Linked list head double pointer passing

I have seen this in some book/ tutorial. When you pass in the head pointer (of linked list) into a function, you need to pass it as a double pointer. For eg: // This is to reverse a linked list where head points to first node. void nReverse(digit…
JohnH
  • 150
  • 1
  • 11
3
votes
7 answers

How do I properly turn a const char* returned from a function into a const char** in C?

In short, I would like to do this: const char **stringPtr = &getString(); However, I understand that you can't & on rvalues. So I'm stuck with this: const char *string = getString(); const char **stringPtr = &string; I can live with two lines. Am…
spirulence
  • 701
  • 3
  • 11
3
votes
2 answers

Using single versus double pointers in Linked lists implemented in C

I was writing this code for adding element at the end of linked list: struct node{ int info; struct node* link; }; void append ( struct node **q, int num ) { struct node *temp, *r ; if ( *q == NULL ) // if the list is empty,…
Jatin
  • 14,112
  • 16
  • 49
  • 78
2
votes
3 answers

Difference between **variable and variable[ ] [ ]?

I am not understanding why I have to receive the contents of a 2D array in b[][3] and not in **b? Also how can we do call by value for 2D arrays? Also, the address of a 2D array arr is equal to contents of arr is equal to *arr is equal to…
user1171901
  • 395
  • 3
  • 5
2
votes
3 answers

Delete a node from singly linked list in C

I have been struggling with the program below for a couple of days to figure it out: void *delete_from_list(struct node** list, int n) { struct node *entry = *list; while (entry) { if (entry->value == n) { *list =…
Fary
  • 77
  • 4
2
votes
1 answer

New to pointers trying to figure out why my implementation of a link list doesn't work

I'm brand new to programming in C and trying to figure out pointers. I thought I'd start with trying to write a simple linked list program. The idea in addNote was to iterate along the chain of pointers until I found a pointer to a NULL instead of a…
1
2
3
22 23