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

bookIntroduction to Pointer

A pointer is a variable that stores the memory address of another variable. It allows direct manipulation of memory. Declaration and initialization of a pointer looks like this:

pointer.h

pointer.h

copy
1
int* p_Name = nullptr;
  • int: specifies the base type of the variable that the pointer will point to. In this case, it's an integer;

  • *: called dereference operator, returns the value stored at the address held by a pointer;

  • p_Name: the name of the pointer variable. You can choose any valid variable name;

  • nullptr: is a keyword that represents a null pointer, indicating that it is empty and doesn't point to anything.

Note

Commonly, pointers are named with a prefix p_ as a naming convention signifying that the variable is a pointer.

Opgave

Swipe to start coding

  1. Declare and initialize pointer with a nullptr.
  2. Display a pointer for a chosen primitive data type.
  3. Make sure its name has p_ prefix.

Løsning

solution.cpp

solution.cpp

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 1
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:

Opsummér dette kapitel

Explain code

Explain why doesn't solve task

close

Awesome!

Completion rate improved to 5.88

bookIntroduction to Pointer

Stryg for at vise menuen

A pointer is a variable that stores the memory address of another variable. It allows direct manipulation of memory. Declaration and initialization of a pointer looks like this:

pointer.h

pointer.h

copy
1
int* p_Name = nullptr;
  • int: specifies the base type of the variable that the pointer will point to. In this case, it's an integer;

  • *: called dereference operator, returns the value stored at the address held by a pointer;

  • p_Name: the name of the pointer variable. You can choose any valid variable name;

  • nullptr: is a keyword that represents a null pointer, indicating that it is empty and doesn't point to anything.

Note

Commonly, pointers are named with a prefix p_ as a naming convention signifying that the variable is a pointer.

Opgave

Swipe to start coding

  1. Declare and initialize pointer with a nullptr.
  2. Display a pointer for a chosen primitive data type.
  3. Make sure its name has p_ prefix.

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 1. Kapitel 1
single

single

some-alt