Answer the question
In order to leave comments, you need to log in
How to understand how to use variables, pointers and references in C++?
Hello, I am learning C++
Theory regarding:
Answer the question
In order to leave comments, you need to log in
In function parameter:
In return value:
In the class field:
Note 1. There are types that are expensive or impossible to move: large std::array
, std::fstream
. If we want to pass the owner of a variable of this type or, for example, return from a function, then we have to use std::unique_ptr
.
Note 2. "Need to be modified" means that we want changes to the object to be visible outside the function. It is possible and necessary to get by with a constant reference, if it is permissible to copy a variable and modify it inside a function.
Practice will save you. Over time, you will understand where you need it.
To get closer to understanding, you can try to answer the following questions yourself:
- what if you need to get two values as a result of executing a function?
- you need to pass to the Bitmap function. How will you transmit it?
- you need to create a singly linked list. Describe its structure.
- you have two arrays of the same type. And there are two functions that modify an array of the same type in different ways. What will be the function prototypes?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question