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".

190 questions
42
votes
14 answers

What does ** do in C language?

I'm new to C with a good background in java and I'm trying to understand pointers and arrays. I know that subscript operator[] is part of an array definition, so: int numbers[] = {1,3,4,5}; would create a integer array, which would be represented…
James
  • 1,179
  • 1
  • 9
  • 20
22
votes
4 answers

Dynamic memory allocation for pointer arrays

I'm am trying to write a program that reads in a series of strings from a text file and stores these in an array of strings, dynamically allocating memory for each element. My plan was to store each string in an array using a pointer and then grow…
14
votes
4 answers

How to work with pointer to pointer to structure in C?

I want to change member of structure under double pointer. Do you know how? Example code typedef struct { int member; } Ttype; void changeMember(Ttype **foo) { //I don`t know how to do it //maybe *foo->member = 1; }
user43975
  • 143
  • 1
  • 2
  • 6
10
votes
1 answer

Why the second argument to pthread_join() is a **, a pointer to a pointer?

I am new to using pthread and also not that familiar with pointers to pointers. Could somebody perhaps explain why the second argument of pthread_join() is a void **. Why is it designed like this. int pthread_join(pthread_t thread, void…
artic sol
  • 301
  • 4
  • 17
6
votes
2 answers

Multi-dimensional array and pointer to pointers

When you create the multi-dimensional array char a[10][10], according to my book it says you must use a parameter similar to char a[][10] to pass the array to a function. Why must you specify the length as such? Aren't you just passing a double…
rubixibuc
  • 6,013
  • 18
  • 50
  • 86
6
votes
2 answers

malloc and pointers to pointers

I'm trying to understand when I need to use malloc when using multiple levels of pointers. For example, #include #include #include int main() { typedef struct { char first[10]; char last[10]; …
Idr
  • 5,174
  • 4
  • 31
  • 44
6
votes
2 answers

Regarding double and triple pointers/double dimension arrays

So, i was playing with C pointers and pointer arithmetic since i'm not entirely comfortable with them. I came up with this code. char* a[5] = { "Hi", "My", "Name", "Is" , "Dennis"}; char** aPtr = a; // This is acceptable because 'a' is double…
user4709059
  • 125
  • 8
6
votes
5 answers

Not able to understand the notations : * and ** with pointers

I have a problem with the pointers. I know what this does: *name I understand that this is a pointer. I've been searching but I do neither understand what this one does nor I've found helpful information **name The context is int **name, not…
MLMH
  • 141
  • 8
6
votes
7 answers

Why should I use double pointer variable to receive another pointer's address(&ptr1)

int num = 45,*ptr1,*ptr2; ptr1=# ptr2=&ptr1; printf("%d\n",*ptr1); I've been thinking about this question for a while, but couldn't find a way to understand it,why &ptr1 can not be assigned to ptr2 in line 3, &ptr1 is a pointer's address,this…
user2556058
  • 301
  • 3
  • 9
5
votes
4 answers

What happens to a pointer to another pointer when the first one is freed?

I have made a simulation of a stack using malloc to create an array of MAX elements and assign it to a pointer. I then made a second pointer pointing to the first one, to be able to navigate back and forth, executing pushes and pops. int * stack=…
Georgy90
  • 135
  • 1
  • 6
4
votes
3 answers

The function only works with a useless printf

I usually try hard and harder to solve myself any bugs I find in my code, but this one is totally out of any logic for me. It works really fine with whatever strings and char separators, but only with that useless printf inside the while of the…
user9997980
4
votes
1 answer

How to use pointer-to-pointer's variables?

I am trying this code: int x[] = {1,5}; int y[] = {3,6}; int *w[] = {x,y}; int **z = w; printf("%d", **z[1]); cout<<**z[0]; But it doesn't work. My goal is to access to each element inside the x or y arrays. My question comes from this part of a…
Hasani
  • 959
  • 1
  • 7
  • 23
4
votes
3 answers

NSError object already populated on first method call

I am following the book Test-Driven iOS development by G. Lee and came across this unit test, which I don't understand. First of all, if you need more code, please let me know right away. -(void)testDelegateNotifiedOfErrorWhenNewsBuilderFails { …
Houman
  • 58,044
  • 75
  • 235
  • 407
4
votes
1 answer

Void pointer pointer (void **)

I am reading a COM sample at http://msdn.microsoft.com/en-us/library/windows/desktop/dd389098(v=vs.85).aspx I really cannot comprehend (void **) in hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); So I have tried some values…
Trio Cheung
  • 1,394
  • 3
  • 17
  • 30
3
votes
2 answers

Incompatible pointer type warning with pointer-to-pointer types when passing char** to void** function parameter

I'm trying to implement a secure-free function that erases the allocated memory, frees it and then also sets the pointer to the allocated region to NULL so the pointer cannot be reused after-free and cannot be double-freed with the same function. To…
Matjaž
  • 260
  • 3
  • 10
1
2 3
12 13