Homework is over pointers

1. (3 points) True or false?
If (x == y) then (&x == &y). T F
Explain your choice:
I think its true but I don't really understand why

If (x == y) then (*x == *y). T F
Explain your choice:
False but not sure why

What school subject is this? I doubt anyone here knows what C++ means.

#1 If x and y are numbers, then &x and &y are their addresses. So, False.

#2 If x and y are pointers, then since they point to the same thing, the values pointed to are equal. So, True.

To understand the answers to these questions about pointers, let's first clarify what pointers are in programming. Pointers are variables that store memory addresses, allowing access to the data stored at that location. The value of a pointer is the memory address it points to, while the dereferencing operator (*) allows access to the value stored at that memory address.

Now, let's analyze each statement:

1. If (x == y), then (&x == &y).
This statement compares whether the variables x and y have the same value. In this case, we are comparing memory addresses with the expression (&x == &y), which checks if the memory address of x is the same as the memory address of y.

If x and y have the same value, it is not necessarily true that their memory addresses are also the same. Variables can have the same value but be stored in different memory locations. Therefore, the statement is False.

Explain your choice: The comparison is between the memory addresses, not the values. So, even if two variables have the same value, if they are stored in different memory locations, their addresses will be different.

2. If (x == y), then (*x == *y).
This statement compares whether the values pointed to by x and y are the same. In this case, we use the dereferencing operator (*) to access the values stored at the addresses pointed to by x and y.

If x and y have the same value, then their memory addresses may or may not be the same. However, if the memory addresses are different, it does not necessarily mean that the values stored at those addresses are different. Therefore, the statement is True.

Explain your choice: Since we are comparing the values pointed to by the pointers, if x and y have the same value, then *x and *y will also have the same value.