const char *v1="testing const char";
char *c = "test char";
String s1="test string";
String *s2;
int i=10;
byte b=12;
//int* i2=20; //Error
//int *i3=30; //Error
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Serial.println(s1); //out- test string
Serial.println(c); //out- test char
Serial.println(*c); //out- t
//Serial.println(s2); //error: no matching function for call to 'println(String*&)'
Serial.println(v1); //out- testing const char
Serial.println(*v1); //out- t
Serial.println(*(v1+6)); //out- g
//v1=s1[]; //error: expected primary-expression before ']' token v1=s1[];
//v1=&s1 //error
//c=&s1; //error: cannot convert 'String*' to 'char*'
//c=s2; //error: cannot convert 'String*' to 'char*'
//c=s1[]; //error: expected primary-expression before ']' token c=s1[];
//c=s1[0]; //error: invalid conversion from 'char' to 'char*' [-fpermissive]
char Buf[50];
s1.toCharArray(Buf, 50);
Serial.println(s1);
Serial.println(Buf);
const char *cid = s1.c_str();
//f1(s1); //error: no matching function for call to 'f1(String&)'
//f1(&s1); //error: no matching function for call to 'f1(String*)'
//f1(*s1); //error: no match for 'operator*' (operand type is 'String')
f1(s1.c_str()); //out- test string
f1(Buf); //out- test string
f1(v1); //out- testing const char
f1(c); //out- test char
//f2(s1.c_str()); //error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
f2(Buf); //out- test string
//f2(v1); //error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
f2(c); //out- test char
f0(s1); //out- test string
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
void f0(String s){
f1(s.c_str());
}
void f1(const char* sn){
Serial.println(sn);
}
void f2(char* sn){
Serial.println(sn);
}