0
pointers are confusing me HELP!
#include <stdio.h> void func(char * data){ printf("%s",data); } int main() { char payload[30] = "this is random data ...\n"; void * ptr; ptr = &payload; //HERE ! // i saw someone using (char *) before the name of the variable and when i tried it it gave me the same output as the function without it ... can someone tell me why he used it ? func(ptr); func((char *)ptr); return 0; } output: this is random data ... this is random data ...
3 ответов
+ 2
So it just a implicit and explicit typecasting, void can type cast to any type
+ 2
To conform with function signature which accepts char* argument probably. Had you defined <ptr> as char* rather than void*, there will be no need for explicit casting on function call.
+ 1
I don't know how to explain it to you, but I know something that can help. Thank me later ;) https://youtube.com/playlist?list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_