Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Pointers Use Cases | Pointers Fundamentals
course content

Conteúdo do Curso

C++ Pointers and References

Pointers Use CasesPointers Use Cases

When you pass a variable to a function, you're essentially passing its value. This means the function receives a copy of the data. Any modifications made inside the function DO NOT affect the original variable.

cpp

main.cpp

We can use pointers to enable a function to alter the original variable. This involves passing a memory address as an argument instead of the actual value.

cpp

main.cpp

Note

You can bypass the creation of a pointer to a variable and instead directly use the address-of operator when passing a variable.

Tarefa

  • Create a function that swaps values of two variables.
  • Call this function.
  • Output the values of variables after the swap.

Tudo estava claro?

Seção 1. Capítulo 4
toggle bottom row
course content

Conteúdo do Curso

C++ Pointers and References

Pointers Use CasesPointers Use Cases

When you pass a variable to a function, you're essentially passing its value. This means the function receives a copy of the data. Any modifications made inside the function DO NOT affect the original variable.

cpp

main.cpp

We can use pointers to enable a function to alter the original variable. This involves passing a memory address as an argument instead of the actual value.

cpp

main.cpp

Note

You can bypass the creation of a pointer to a variable and instead directly use the address-of operator when passing a variable.

Tarefa

  • Create a function that swaps values of two variables.
  • Call this function.
  • Output the values of variables after the swap.

Tudo estava claro?

Seção 1. Capítulo 4
toggle bottom row
some-alt