본문 바로가기

Computer Engineering

[C++] const 상수로 정의하면

#include <iostream>

using namespace std;

int main()
{
  const unsigned short studentPerClass = 30;
  // studentPerClass = 50; //변경이 불가능함.
 => 위의 주석을 제거해서 컴파일을 시도하면
error: assignment of read-only variable 이라는 에러가 발생한다.
  cout<< studentPerClass << endl;

  return 0;
}

'Computer Engineering' 카테고리의 다른 글