Difficult C++ pointer question, PLEASE HELP!!!!?

 Dont Buy Textbooks. Rent 'EM Save 60-80%



I'm reading this tutorial on c++, apparently when you define a pointer to be const, the address of that pointer can not be changed. However the below code defines a pointer as const called pointer and points to the address of variable a1, however i then give the pointer a new address (variable a2). I'm really confused because point was declared as a constant, yet a can change the address of the pointer and the program compiles with out any errors. can any body explain to whats happening and y my theory isn't working?

#include<iostream>

int main()

{

int a1 = 1, a2 = 2;

int const *point = 0;

point = &a1;

std::cout<<*point<<'\n';

point = &a2;

std::cout<<*point<<'\n';

system("pause");

return 0;

}

output:

--------

1

2

press any key to continue........

Difficult C++ pointer question, PLEASE HELP!!!!?c++ runtime error



the compiler interprets

int const *point

as

const int *point

which mean it is a pointer to a constant integer.

change it to

int * const point

will cause the pointer point to not be changed.

Difficult C++ pointer question, PLEASE HELP!!!!?c++ standard




FirstPrevious12NextEnd

More Related Questions and Answers ...
  • Need help fixing the errors in this Template ..
  • Please give me short note of my C++ program....
  • Basic C syntax, assigning a value?
  • C++ new comer question?
  • Need help creating c++ set class?
  • My C++ program has only 3 error...so pl corre..
  • C++ Linker Error Please Help! Why am I gettin..
  • PLease provide a short explanation with each ..
  • C++ ifstream stream question?
  • C++ Program Help! (Using classes)?
  • C++ Build Solution problem?
  • What is difference between c++ const and c co..
  • C++ compilers!!!!!!!!!!!!?????????...
  • C++ compilers?
  • How C Compilers work?
  • Are there any c++ compilers for palm?
  • What are the other COMPILERS that i can use o..
  • Please can someone enlist some good free C++ ..
  • Compatability between C/C++ compilers?

  • The information post by website user , we not guarantee correctness.

    

    Dental Treatment Skin Whitening Skin Problems Skin Rashes Shoes