0
What's the difference between have a double pointer and have two separet pointers??
I need help :)
3 Antworten
+ 5
for single values, double pointers may seem useless. creating a second pointer to the same value does the same thing.
but it's useful for working with array of pointers , array of strings or 2d arrays
https://www.geeksforgeeks.org/c-pointer-to-pointer-double-pointer/
+ 4
a double pointer points to a pointer
After all, pointers themselves need memory space
int x = 0;
int *ptr1 = &x;
// one entity that points to a pointer
int **ptr2 = &ptr1;
two separate pointers are two different pointer objects/types
int x = 0;
// seperate entities that dont rely on each other
int *ptr1 = &x;
int *ptr2 = &x;
0
(1)A double pointer is a pointer that stores the address of another pointer.
int x = 10;
int *p = &x;
int **pp = &p;
x is an integer.
p points to x.
pp points to p — it’s a double pointer.
(2)Two Separate Pointers
This means you have two independent pointers, each pointing to their own (or maybe the same) data.
int a = 5, b = 6;
int *p1 = &a;
int *p2 = &b;
p1 and p2 are not related.
Each stores the address of a separate variable.