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
26
votes
8 answers

How to qsort an array of pointers to char in C?

Suppose I have an array of pointers to char in C: char *data[5] = { "boda", "cydo", "washington", "dc", "obama" }; And I wish to sort this array using qsort: qsort(data, 5, sizeof(char *), compare_function); I am unable to come up with the compare…
bodacydo
  • 63,809
  • 83
  • 206
  • 303
19
votes
7 answers

Assigning memory to double pointer?

I am having trouble understanding how to assign memory to a double pointer. I want to read an array of strings and store it. char **ptr; fp = fopen("file.txt","r"); ptr = (char**)malloc(sizeof(char*)*50); for(int i=0; i<20; i++) …
lazy_hack
  • 281
  • 1
  • 2
  • 6
14
votes
3 answers

Converting from a jagged array to double pointer in C#

Simple question here: is there any way to convert from a jagged array to a double pointer? e.g. Convert a double[][] to double** This can't be done just by casting unfortunately (as it can in plain old C), unfortunately. Using a fixed statement…
Noldorin
  • 134,265
  • 53
  • 250
  • 293
8
votes
3 answers

Is it Legal to reinterpret_cast to a void*

I was looking at https://en.cppreference.com/w/cpp/language/reinterpret_cast and I noticed that it specifies the legal types we can always cast to: byte* char* unsigned char* But I did not see void* in the list. Is this an oversight? My use case…
Jonathan Mee
  • 35,107
  • 16
  • 95
  • 241
8
votes
5 answers

Two Dimensional Array Implementation Using Double Pointer

Please consider the following code: #include #include #define NUM_ARRAYS 4 #define NUM_ELEMENTS 4 #define INVALID_VAL -1 int main() { int index = INVALID_VAL; int array_index = INVALID_VAL; int…
Sandeep Singh
  • 4,354
  • 7
  • 33
  • 55
7
votes
2 answers

How to get size of 2D array pointed by a double pointer?

I am trying to get the number of rows and columns of a 2D Array from a double pointer pointed to the array. #include #include void get_details(int **a) { int row = ??? // how get no. of rows int column = ??? // how…
Yash
  • 83
  • 1
  • 2
  • 4
6
votes
1 answer

How to write SQLite callback in COBOL

I'm a COBOL programmer , and my latest project is to connect a COBOL application to a SQLite3 database. I have been following this guide, and their solution is exactly what I would need in my COBOL application. I have successfully managed to create,…
6
votes
1 answer

how to declare variable of NSString with double pointer

I wanna use double pointer and I tried to declare like this. NSString **a; but, Xcode showed me the error "Pointer to non-const type 'NSString *' with no explicit ownership" and it couldn't be compiled. Finally I wanna do like this. NSString…
6
votes
2 answers

unsigned char ** to opencv mat

I'm almost there but I can't quite understand how to convert unsigned char ** to a cv::Mat I know that the .data part of a cv::Mat is uchar* I'm using a function that returns and image in the form of... unsigned char ** output; But the rest of my…
Oliver9523
  • 383
  • 1
  • 4
  • 16
5
votes
3 answers

Return a read-only double pointer

I want to a member variable, which is a double pointer. The object, the double pointer points to shall not be modified from outside the class. My following try yields an "invalid conversion from ‘std::string**’ to ‘const std::string**’" class…
Hugo
  • 53
  • 4
5
votes
5 answers

C# References; Keeping Members Hidden

Imagine you have a class defined as follows. public class SomeClass { public Manager m { get; protected set; } public SpecialData data { get; protected set; } //More methods and member code here... } I need my manager class to…
guitar80
  • 696
  • 6
  • 16
5
votes
4 answers

usage of double pointers as arguments

Please find the code snippet as shown below: #include int My_func(int **); int main() { int a =5; int *p = &a; My_Func(&p); printf("The val of *p is %d\n,*p); } void My_Func(int **p) { int val = 100; …
Maddy
  • 423
  • 4
  • 11
  • 19
4
votes
2 answers

Why do I Have to reinterpret_cast Pointer Pointers?

So this static_cast code is totally legal: int n = 13; void* pn = static_cast(&n); void** ppn = &pn; Yet this has to be made into a reinterpret_cast to compile: int n = 13; int* foo = &n; void** bar = static_cast(&foo); If I don't…
Jonathan Mee
  • 35,107
  • 16
  • 95
  • 241
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…
1
2 3
18 19