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

1. Consider the following code (assume proper includes, etc): int main() { (a) W

ID: 3792461 • Letter: 1

Question

1. Consider the following code (assume proper includes, etc):

int main() {

(a) Which statements of the code marked for part (a) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(b) Which statements of the code marked for part (b) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(c) Which statements of the code marked for part (c) are valid, and which statements are invalid? If a statement is invalid, please explain why.

2. Consider the following code (assume proper includes, etc):

int main() {

(a) Which statements of the code marked for part (a) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(b) Which statements of the code marked for part (b) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(c) Which statements of the code marked for part (c) are valid, and which statements are invalid? If a statement is invalid, please explain why.

3. Consider the following code (assume proper includes, etc):

} // foo

} // bar

(a) Which statements of the code marked for part (a) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(b) Which statements of the code marked for part (b) are valid, and which statements are invalid? If a statement is invalid, please explain why.

(c) Which statements of the code marked for part (c) are valid, and which statements are invalid? If a statement is invalid, please explain why.

Explanation / Answer

Hi, I have answered all parts of first question.

Please repost other questions in separate post.

#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
int x = 44;
int y = 22;

// part (a)
int * p1 = &x; // this is VALID
*p1 = 11; // this is VALID

// part (b)
const int * p2 = &x; // this is VALID
*p2 = 11; // Not VALID, because p2 is constnt, so its value can not be changed
p2 = &y; // this is VALID

// part (c)
const int * const p3 = &x; // this is VALID
*p3 = 11; // Not VALID, because p3 is constnt, so its value can not be changed
p3 = &y; // Not VALID, because p3 is constnt pointer, so it can not point to other address

return EXIT_SUCCESS;
} // main

Please let me know in case of any issue in first part