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

bookChallenge: Pointer Arithmetic

Uppgift

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 allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2
single

single

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

close

Awesome!

Completion rate improved to 5.88

bookChallenge: Pointer Arithmetic

Svep för att visa menyn

Uppgift

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 desktopByt till skrivbordet för praktisk övningFortsätt där du är med ett av alternativen nedan
Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 2. Kapitel 2
single

single

some-alt