Will the following code compile? If no - which lines will compilation errors occur in?
After C++14 standard.
int main()
{
    const int* i = int(); // 1
    int const* j = int(); //2
    int* const k = int(); //3
    int* l(); //4

    ++i; //5
    ++j; //6
    ++k; //7
    ++*k; //8
    ++l; //9
}
Explanation
Compilation errors will occur in lines:
  • error: cannot initialize a variable of type 'const int *' with an rvalue of type 'int' const int* i = int(); //1
  • error: cannot initialize a variable of type 'const int *' with an rvalue of type 'int' int const* j = int(); //2
  • error: cannot initialize a variable of type 'int *const' with an rvalue of type 'int' int* const k = int(); //3
  • error: cannot increment value of type 'int *()' ++l; //9

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты