couple questions about C++

1. All of the following options below are valid arithmetic operations that can be performed on pointers EXCEPT:

A.
Add one pointer to another pointer (ptr1 + ptr2)

B.
Add an integer to a pointer (ptr + i)

C.
Subtract an integer from a pointer (ptr – i)

D.
Subtract one pointer from another pointer (ptr1 – ptr2)


2. Logically (i.e., as a concept), objects consist of _
Physically (i.e., in memory), objects consist of _

A.
Only member variables
Both member variables and member functions

B.
Only member variables
Only member variables

C.
Both member variables and member functions
Only member variables

D.
Both member variables and member functions
Both member variables and member functions

3. The unary operator _ determines the size of any data type
This operator returns the number of _ that the data type takes up in memory

A.
1. sizeof
2. bits

B.
1-. sizeof
2-. bytes

C.
1. size
2. bytes

D.
1. size
2. bits

4. What is the relationship between throw, try, and catch?

A.
Throw signals that an exception has occurred
Try handles an exception
Catch contains code that could possibly cause an exception

B.
Throw signals that an exception has occurred
Try contains code that could possibly cause an exception
Catch handles an exception

C.
Throw handles an exception
Try contains code that could possibly cause an exception
Catch signals that an exception has occurred

D.
Throw handles an exception
Try signals that an exception has occurred
Catch contains code that could possibly cause an exception

5. int x = 7;

int * const ptr = &x;

Which of the options below accurately describes ptr?

A.
Nonconstant pointer to nonconstant data

B.
Constant pointer to constant data

C.
Nonconstant pointer to constant data

D.
Constant pointer to nonconstant data





Can anyone tell me the correct answers and why?? please
Last edited on
I'm a noob. According to this link tho

1. B
https://www.ics.com/designpatterns/book/pointerops.html
Last edited on
no, it helps a lot, thank you so much. btw, I didn't see where said B is correct :(..
is that because they are not the same type?
Last edited on
Yeah it doesn't exactly say B is incorrect but it does say the other ones are correct tho. doesnt directly say B is incorrect.
The page that r6racer linked to says the following.

Following is a list of the operations that can properly be performed with pointers.
[...]
Arithmetic
[...]
• Adding or subtracting an integer: p + k and p - k

This means B is one of the valid operations that can be performed on pointers.
Peter is def right, idk how I put B last night. From what i remember concluding the answer was A.
Topic archived. No new replies allowed.