Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exercise: pointers and references in C++

Is this correct:

a) Pointer p1 to a char:

char* p1;

b) A constant pointer p2 to a char:

char* const p2;

c) pointer p3 to a constant char:

const char* p3;

d) A constant pointer p4 to a constant char:

const char* const p4;

e) A reference r1 to a char:

char & r1;

f) A reference r2 to a constant char:

const char& r2;

Would you please notify me any mistakes?

like image 762
laika Avatar asked Jun 26 '11 18:06

laika


People also ask

What is pointers in C with example?

A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) an integer value, however an integer pointer holds the address of a integer variable.

What are pointers in C?

A pointer is a variable that stores the memory address of another variable as its value.


1 Answers

They are all correct. I can't see any mistakes :-)

like image 148
Peter Alexander Avatar answered Oct 13 '22 22:10

Peter Alexander