126k views
5 votes
The asterisk is used to dereference a pointer. The result returned is a copy of the contents of the memory location addressed by the pointer. Which line choice below shows this concept (listing 1)? Option 1: int x = ptr; Option 2: int x = &ptr; Option 3: int x = ptr; Option 4: int x = &*ptr;

User Selmar
by
7.7k points

1 Answer

4 votes
Option 4: int x = &*ptr;

In this line, the asterisk (*) is used to dereference the pointer "ptr," and the ampersand (&) is then used to get the address of the dereferenced value. This results in "x" containing the address of the value pointed to by "ptr," making it a valid way to use the concept of dereferencing a pointer.
User Lakhan Sharma
by
8.2k points