I am currently analysing the char and string datatypes. For char data types, the following code snipped holds good:
char value = 'a';
char value1[] = "Good";
char* value2 = "Good";
For strings,
string strValue = "Good";
string strVal[3] = {"Good","Better","Best"};
But the assignment below throws the compilation error:
"error: scalar object strPtr requires one element in initializer"
string* strPtr = {"Good","Better","Best"}
So, how to assign values to above string* initially?
Thanks, Udhai
Pointers are not arrays, so why would you want to pretend otherwise? You could do this however
string strVal[3] = {"Good","Better","Best"};
string* strPtr = strVal;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With