I was asked a question on an assignment about stings. The question asked:
Given the declaration: char myString[16];
Which of the following statements is valid? If a statement is invalid, provide the correct syntax.
a. strcpy(myString, “Hello the world”);
b. strlen(myString);
c. myString = “Marylane”;
d. cin.getline(myString, 80);
e. cout << myString;
f. if (myString >= “Nice day”)
cout << myString;
g. myString[6] = ‘t’;
The I have been able to compile several of these sections as follows:
/*b.*/ int len;
len = strlen(myString);
/*c.*/ strcpy(myString, “Hello the world”);
/*f.*/ int strTest;
strTest = strcmp(myString, "Nice day");
if (strTest < 0)
cout << myString << endl;
else
{
cout << "No Dice" << endl;
}
I assumed 'g' would be invalid because I thought you could not use a assignment operators, but I got it to compile. Can anyone explain that?