String str = "Hello World"; char charArray[20]; str.toCharArray(charArray, 20);
String str = "12345"; char charArray[6]; str.toCharArray(charArray, 6);In this example, the string "12345" is assigned to the variable 'str'. Then, using the toCharArray function, it is converted to an array of characters and stored in the 'charArray' variable. However, note that the size of the array is 6 instead of 5, which is the length of the string. This is because the array needs an extra space for the null character ('\0') at the end of the array. Overall, the toCharArray function is useful in situations where a function or library requires a character array as input instead of a string object.