C++ PROGRAMMING QUESTION For the code given below, what is the output and the va
ID: 3937055 • Letter: C
Question
C++ PROGRAMMING QUESTION
For the code given below, what is the output and the value of variable d after execution when using the following 4 variable initialization options. Explain your answers (notice there are no spaces within the strings): char a[]="way"; char b[]="whey"; char a[]="whey"; char b[]="way"; char a[]="one, two, three"; char b[]="one, two, three"; char a[]="I'mGonnaGoMyWay"; char b[]="I'mGonnaGoMyWaY"; int main() {char a[]="_"; char b[]="_"; string c; int d=strcmp(a, b); if (d) c=" NOT "; else c=" "; coutExplanation / Answer
for option a output is
Strings are NOT the same! because way is lexicographically smaller than whey. hence the value returned will be <0 which is true for if statement.
for option b output is
Strings are NOT the same! because whey is lexicographically greater than way. hence the value returned will be >0 which is true for if statement.
for option c output is
Strings are the same! because both the string are equal and strcmp will return 0 when both strings are equal hence the if statement evaluates to false..
for option d output is
Strings are NOT the same! because I'mGonnaGoMyWay is lexicographically greater than I'mGonnaGoMyWaY. hence the value returned will be >0 which is true for if statement.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.