Home > Mobile >  assiging pointer to pointer to char pointer such that allocation done in called function and paramet
assiging pointer to pointer to char pointer such that allocation done in called function and paramet

Time:12-05

I have a pointer to poinetr that I am getting in function as parameter char **image

now I want to assign it to char pointer such that if I allocate disk then the calling function of test can free it image and disk will be freed too. Is it possible in C? This is my function that calling function is calling and image is pointer to pointer parameter. I calling this function as char *image="hello";test("hello",&image)

int32_t test(const char *path,char **image){

*(char *)(&disk) =*image;
34       printf("ya %s\n",*disk);

CodePudding user response:

*(char *)(&disk)
          ^^^^^  take the address of disk (with type "pointer to type of disk")
 ^^^^^^^^^     ^ convert that to a pointer to char
^                and finally get the single char pointed to by that mess

*(char *)(&disk) = *image; // nope, you cannot assign a pointer to char to a char.
  •  Tags:  
  • c
  • Related