Convert uint8_t* to char* in C++

Do not miss this exclusive book on Binary Tree Problems. Get it now for free.

In this article, we have presented how to convert an array of uint8_t (uint8_t*) to an array of char (char*).

Convert uint8_t * to char * in C

uint8_t and char both are of size 8 bits. Moreover, uint8_t is a typedef for char and hence, there will be no loss in conversion if an uint8_t variable is casted to become a char.

uint8_t input = 12;
char input2 = (char) input;

If we are dealing with an array or vector of uint8_t, the process is similar. Just cast the vector to char*.

uint8_t* input = {12, 1, 65, 90};
char* input2 = (char *) input;

Following is the complete C++ converting uint8_t* to char*:

#include <stdlib.h>

int main() {
  uint8_t* input = {12, 1, 65, 90};
  char* input2 = (char *) input;
  return 0;
}

With this article at OpenGenus, you must have the complete idea of how to convert uint8_t* to char*.

Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.