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

I am having trouble understanding these C++ programming questions. Can anyone ex

ID: 3699095 • Letter: I

Question

I am having trouble understanding these C++ programming questions. Can anyone explain to how to solve them and why an answer is correct?

1.) How many lines in the code segment below contain syntax errors?

char* CastleofSteel(char* Thor)

{

Thor = "Thunder-God";

return Thor;

}

int main()

{

char castle = 'A', *ptr;

ptr = CastleofSteel(&castle);

return 0;

}

Possible Answers:

a.) 0

b.) 1

c.) 2

d.) 3

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

2.) What is the output of the following code segment? (NOTE: sizeof() returns the number of bytes the variable uses in memory)

int maxChars; const int SIZE_1 = 25;

const int SIZE_2 = 25;

char string1[SIZE_1] = "Justice League:";

char string2[SIZE_2] = " Battle for Metropolis";

maxChars = sizeof(string1) - (strlen(string1) + 1);

strncat(string1, string2, maxChars);

cout << string1 << endl;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

3.) Choose the pointer declaration statement below that will prevent the pointer from being moved, but will allow the data to be modified.

Possible Answer Choices:

a.) bool boat[4][4];

const bool *Spiderman_Showdown = &boat[0][0];

b.) bool boat[4][4];

bool * const Spiderman_Showdown = &boat[0][0];

c.) bool boat[4][4];

bool *Spiderman_Showdown = &boat[0][0];

d.) bool boat[4][4];

bool *Spiderman_Showdown = const &boat[0][0];

Explanation / Answer

2)

3)

b.) bool boat[4][4];

bool * const Spiderman_Showdown = &boat[0][0];

is the correct answer for given condition

it will make the address which Spiderman_Showdown pointing fixed i.e whatever address stored in Spiderman_Showdown can not be modified if anyone want to do so compiler will flag an error but the help of this pointer data of 2D bool array boat can be modified