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.

285 questions
-2
votes
2 answers

Pointer with double pointer

Why cant I assign a pointer to a double pointer's pointer? I get segmentation fault every time. #include int main() { int **pointer1, *pointer2, *pointer3, var; var = 10; pointer3 = &var; pointer1 = &pointer3; …
-2
votes
1 answer

In C, How do you access elements in an array through a double pointer

I am trying to write a program for my class but I can't get started because I don't know how to access the function's argument elements. A char array is passed into the function like this: RPN_calculator(input1) where input1 is a pointer to an…
-2
votes
1 answer

Segmentation fault when using strcpy on double pointer

I'm pretty new to C, but have programmed a great deal in both Java and Python. So I got the basics going – however, C keeps hitting me with this Segmentation fault: 11 no matter how I wrap my head around my code. I suspect the problem may be that…
-2
votes
1 answer

Double pointer wont store pointer value correctly and not freeing right

Im using a series of double pointers that point to other double pointers. Currently i have a struct that points to other structs that have double pointers. I was using the "sprintf" command to store values and it was working great until i…
MunajSyed
  • 19
  • 3
-2
votes
1 answer

Difficulties about structure and pointers in C

I'm currently facing some problems accessing a double pointer. 1. The double pointer that is an element of a structure. 2. The double pointer is also instance of another structure. 3. That structure also contains an element that is explicitly a…
-2
votes
2 answers

Using double pointers in stuct

Let's say i have a student struct defined: stuct student { struct Student *next; }; typedef struct student Student Now I have the following function: void add_student(Student **student_list_ptr) { Student *new_s; new_s =…
-2
votes
1 answer

Memory allocation for array of structures? 2 examples

I am having the following situation, an array of structs passed to a function. So, inside function I'm dealing with double pointer. Now I am confused, it is working but I'm not sure why is it working on both ways(I like to try things out in…
-2
votes
2 answers

The same variable shared between double pointer and single pointer

Good evening, quick question regarding the following code: // Start of main int i,j; int row,col; printf("Enter the values for row and col:\n"); scanf("%d%d",&row,&col); int **arr=(int**)malloc(row*(sizeof(int*))); for(i=0; i
Shady Programmer
  • 754
  • 3
  • 9
  • 21
-2
votes
1 answer

pointer to pointer to structure with malloc and strdup

My main intention is to pass a pointer to a structure, to a function, which will allocate memory and fill all its values. After returning back i will print it on screen. Structure looks like this. struct isolock{ char *name; unsigned int…
-3
votes
2 answers

Segmentation fault when initializing 2D array in c

I am declaring a 2d array in a headers file like this : int **arr; Then I'm allocating memory and I initialize it with zeros. However I'm getting segmentation fault. Here is my code : arr = (int **)malloc(d * sizeof(int *)); for (int u=0; u
-3
votes
1 answer

Freeing linked list crashes when on last node

This is a continuation of a problem I posted yesterday, which I thought was solved, but turns out another problem has been encountered with the way I iterate through the loop and its exit condition. I felt a new question thread might be more…
skevthedev
  • 337
  • 1
  • 5
  • 19
-4
votes
2 answers

Local variable values and Address getting retained even after function completes Execution

#include int main() { int var=100; int *ptr=&var; fun(&ptr); printf("%p",ptr); printf("%d\n",*ptr); } int fun(int **var) { int j=10; *var=&j; printf("%p\n",*var); …
Ravi teja
  • 26
  • 4
-4
votes
1 answer

realloc() : Invalid pointer in C

Net is a structure which contain typedef struct net{ int numele; struct net **e; } net; The following code raises the error: realloc(): invalid pointer The realloc is causing problems whenever it is accessed and gives the above error. I…
-5
votes
1 answer

Creating Double Pointer

Can I get to know what is happening in the following commands? Here we have H as a structure with n as an integer type structure element. What is var basically after this? float **var; var = new float* [H.n];
A. Rehman
  • 1
  • 2
-5
votes
2 answers

Learning C++ pointer runs into core dump with following code, I really don't why?

#include int main(){ int *array = new int[2]; array[0] = 1; array[1] = 2; int ** dp = NULL; *dp = array; return 0; } when I run it ,Segmentation fault (core dumped). g++ version is Reading specs from…
imotai
  • 1,686
  • 1
  • 10
  • 9
1 2 3
18
19