Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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=" "; cout

Explanation / 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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote