
В чем принципиальное отличие ссылки от указателя в С++? Какие ограничения есть у первых, а какие у вторых?
Вот некоторые из отличий::
nullptr
:void f(int* num, int& num2)
{
if(num != nullptr) // if nullptr ignored algorithm
{
}
// can't check num2 on need to use or not
}
const
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
const int v = 10;
//int& const r = v; // Ошибка
const int& r = v;
enum
{
is_const = std::is_const<decltype(r)>::value
};
if(!is_const)
std::cout << "const int& r is not const\n";
else
std::cout << "const int& r is const\n";
}
@cpluspluc