I'm new into C and I'm trying to get a grip on pointers. I came across this expression
char *foo = *(char **)bar;
what exactly is going on? I understand that * is pointer ** is pointer to pointer, but I don't really get what is *(char **)bar
edit: worth to mention that bar is declared as const void *bar
*(char**)bar;
Cast bar to a pointer to pointer to char and dereference, which results in a pointer to char (i.e., a char*).
Remember that pointers are merely indirection. When you dereference a pointer you "drop a star", i.e.:
char ***p = ...;
p -> char***
*p -> char**
**p -> char*
***p -> char
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With