I have started learning about Arduino and am well versed in Java and Python. In an Arduino program, I need a character input via Serial to be stored in a String variable. From my previous programming experience, I knew that a code like the one below would give an error as char can't be converted into String like this.
void loop() {
if(Serial.available()) {
String s=(char)Serial.read();
}
}
As expected, the above code gives an error on compiling. But when I first defined s and then assigned its value in a separate step in void loop(), I got no error.
void loop() {
if(Serial.available()) {
String s;
s=(char)Serial.read();
}
}
The above code yields no error despite the fact that it is almost similar to the first code. What I suspect is that there is some different concept of instance variables hereit has something to do with String being a class. Can one tell what is going on?