MCPcopy Create free account
hub / github.com/ShiqiYu/CPP / main

Function main

week05/examples/const-pointer.cpp:13–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13int main()
14{
15 int num = 1;
16 int another = 2;
17
18 //You cannot change the value that p1 points to through p1
19 const int * p1 = #
20 *p1 = 3; //error
21 num = 3; //okay
22
23 //You cannot change value of p2 (address)
24 int * const p2 = #
25 *p2 = 3; //okay
26 p2 = &another; //error
27
28 //You can change neither
29 const int* const p3 = #
30 *p3 = 3; //error
31 p3 = &another; // error
32
33 return 0;
34}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected