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

Conteúdo do Curso

C++ Pointers and References

C++ Pointers and References

1. Pointers Fundamentals
2. Pointer Arithmetic
3. References Fundamentals
4. Dynamic Memory Allocation

bookIntroduction to References

A reference is an alias, or an alternative name, for an existing variable. It provides a way to access the value of a variable indirectly through another name.

They do not have a memory address of their own. Instead they refer to the memory address of the variable they are referencing.

Now, referenceVariable is an alias for originalVariable. The primary purpose of references is to simplify and make safe, more readable code and avoid unnecessary memory overhead.

Advantages of Reference

  • Safe 🛡️: references cannot be null or uninitialized. Also they don't support arithmetic operations reducing the risk of accessing invalid memory;

  • Memory Efficiency ⏱️: references avoid the need for copying large data structures, making code more memory-efficient;

  • Readability 📖: Using references can make code more readable and concise, as they provide a clean way to work with variables;

  • Modifiability 🔧: allow functions to modify the original values directly, providing a convenient way to update variables.
What is false about the references?

What is false about the references?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
some-alt