-9
void main()
{
    int const *p=5;
    cout<<++(*p);
}

What will this do? Is it wrong and if so, why? Please make me understand. Thank you!

Occlet
  • 1
  • 3
  • 5
    It will get you downvotes mostly. To avoid those in the future you should take [the tour](http://stackoverflow.com/tour) and read the [help page](http://stackoverflow.com/help). Here is [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). –  Jan 29 '17 at 23:57
  • What did i do wrong? I am new here, please explain! Thanks – Occlet Jan 29 '17 at 23:59
  • 1
    What does your compiler say when you try to compile this piece of code? – Igor Tandetnik Jan 30 '17 at 00:03
  • _What did i do wrong?_ Well.. For starters - you didn't do _any_ research before asking here. – Algirdas Preidžius Jan 30 '17 at 01:26

1 Answers1

2

What will this do?

The program is ill-formed and may refuse to compile. If it compiles, the behaviour is not specified by the standard.

Is it wrong and if so, why?

It is. Because:

error: '::main' must return 'int'
error: invalid conversion from 'int' to 'const int*'
error: 'cout' was not declared in this scope
error: increment of read-only location '* p'
eerorika
  • 232,697
  • 12
  • 197
  • 326