Convert character array to string in Arduino

In order to convert a character array to a string, the String() constructor can be used. An example is shown below −


void setup() {
   // put your setup code here, to run once:
   char buf[10] = "Hello!";

   Serial.print("Char array: ");
   String s = String(buf);
   Serial.print("String: ");
void loop() {
   // put your main code here, to run repeatedly:

The output of the Serial monitor is shown below −