Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Pointer Arithmetic | Pointer Arithmetic
C++ Pointers and References

bookChallenge: Pointer Arithmetic

Opgave

Swipe to start coding

Sometimes in programming, you may want to access the value of a variable indirectly using a pointer.

In this task, you will write a function that starts with one variable, moves a pointer to another variable, and returns the value stored there.

  1. Calculate the distance between the two pointers by subtracting the address of p_start from the address of p_target.
  2. Add this difference to the p_start pointer. This gives you a pointer to the value stored in p_target.
  3. Return the value pointed to by p_start.

Løsning

solution.cpp

solution.cpp

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you explain this in simpler terms?

What are some examples related to this topic?

Where can I learn more about this?

close

Awesome!

Completion rate improved to 5.88

bookChallenge: Pointer Arithmetic

Stryg for at vise menuen

Opgave

Swipe to start coding

Sometimes in programming, you may want to access the value of a variable indirectly using a pointer.

In this task, you will write a function that starts with one variable, moves a pointer to another variable, and returns the value stored there.

  1. Calculate the distance between the two pointers by subtracting the address of p_start from the address of p_target.
  2. Add this difference to the p_start pointer. This gives you a pointer to the value stored in p_target.
  3. Return the value pointed to by p_start.

Løsning

solution.cpp

solution.cpp

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 2
single

single

some-alt