오토 auto

auto 타입

auto 오토 타입은 우변의 값에 따라 데이터 형이 결정된다. 초기화 시 우변에 값을 반드시 대입해야 한다.

typeid(변수).name() 데이터 형을 반환한다.

실습 예제

ch05ex3_auto.cpp

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	auto v1 = 3;
	auto v2 = 3.14;
	auto v3 = 'T';
	// auto v4; error

	cout << "v1: " << v1 << ", type: " << typeid(v1).name() << endl;
	cout << "v2: " << v2 << ", type: " << typeid(v2).name() << endl;
	cout << "v3: " << v3 << ", type: " << typeid(v3).name() << endl;

	return 0;
}

Last updated