Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Pointers vs References | References & Pointers
C++ Intermediate | Mobile-Friendly
course content

Kurssisisältö

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Pointers vs References

As I already mentioned, you can add to the pointer any number you want to go to the next storage unit. For example:

123456
int a = 1; int *pa = &a; cout << pa << endl; pa++; cout << pa;
copy

Pay attention that we moved forward to 4 bytes (size of the int type). Such math operation is unavailable for references:

123456
int a = 1; int &ra = a; cout << ra << endl; ra++; cout << ra;
copy

We changed the value of the variable a but not the reference.

question mark

What's the difference between a pointer and a reference?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 7

Kysy tekoälyä

expand
ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

course content

Kurssisisältö

C++ Intermediate | Mobile-Friendly

C++ Intermediate | Mobile-Friendly

1. Data Types and Arrays
2. References & Pointers
3. Dynamic Memory
4. Functions

book
Pointers vs References

As I already mentioned, you can add to the pointer any number you want to go to the next storage unit. For example:

123456
int a = 1; int *pa = &a; cout << pa << endl; pa++; cout << pa;
copy

Pay attention that we moved forward to 4 bytes (size of the int type). Such math operation is unavailable for references:

123456
int a = 1; int &ra = a; cout << ra << endl; ra++; cout << ra;
copy

We changed the value of the variable a but not the reference.

question mark

What's the difference between a pointer and a reference?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 2. Luku 7
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt