Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Void ** a generic pointer?

Tags:

c++

c

void * is a generic pointer, but what about void **? Is void ** also a generic pointer?

Can we typecast void ** to int **, char ** and so on.

I would be thankful to stack overflow family for any information on this.

like image 296
Adarsh Avatar asked Aug 21 '14 13:08

Adarsh


People also ask

What is a void generic pointer?

The void pointer in C is a pointer that is not associated with any data types. It points to some data location in the storage. This means that it points to the address of variables. It is also called the general purpose pointer. In C, malloc() and calloc() functions return void * or generic pointers.

Why void pointer is called generic pointer?

Generic Pointers / Void pointerSince you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to cast it to another kind of pointer first. Hence the term Generic pointer.

Is generic pointer same as void pointer?

No difference. void pointer is itself called generic pointer. Show activity on this post. If you declare a pointer to void it's called Generic Pointer since you have to cast it to another kind of pointer first.

What is void * C++?

void (C++) If a pointer's type is void* , the pointer can point to any variable that's not declared with the const or volatile keyword. A void* pointer can't be dereferenced unless it's cast to another type. A void* pointer can be converted into any other type of data pointer.


1 Answers

No. void** is a pointer to void*, and nothing else. Only void* acts like a generic pointer.

Note that actually trying it will probably yield consistent results, but only the above is mandated by the Standard, anything else is Undefined Behaviour and may crash without mercy.

like image 72
Quentin Avatar answered Sep 21 '22 15:09

Quentin