csci3081/constants/constants.cc
Michael Zhang 1ba4536588
f
2018-01-29 17:24:20 -06:00

41 lines
771 B
C++

int main() {
// const int myConst1;
const int myConst1 = 100;
const int myConst2 = 200;
const int* pMyConst;
// init integer
myConst1 = 100;
// init pointer
pMyConst = &myConst2;
// change pointer
pMyConst = &myConst2;
// change integer
myConst2 = myConst2 + 5;
// change integer using pointer
*pMyConst = myConst1 + 1;
int myInt_3;
int myInt_4 = 400;
int* const cpMyInt_3 = &myInt_3;
// initialize the pointer
int* const cpMyInt_4;
int* const cpMyInt_4 = &myInt_4;
// initialize integer
myInt_3 = 300;
// change the integer
myInt_4 = myInt_4 + 5;
// change integer using pointer
*cpMyInt_3 = myInt_4;
// change the pointer
cpMyInt_3 = &myInt_4;
}