정수
종류 | byte |
short | 2 |
int | 4 |
long | 4 |
long long | 8 |
short -32768 ~ 32757
unsigned short 65535
-> unsigned short b = -1; b 출력 시 65535
실수
종류 | byte |
float | 4 |
double | 8 |
long double | 8 |
문자형
char a = 'b';
char a[10] = "apple";
char a[] = {'a', 'b', 'c', '\0'} -> 컴퓨터가 문자열이 끝났음을 인식하려면 '\0' 널문자 필요
char와 string 비교
#include <iostream>
using namespace std;
int main() {
char char1[20];
char char2[20] = "apple";
string str1;
string str2 = "apple";
//char1 = char2; 틀림 배열은 통째로 옮기기 불가능
str1 = str2;
cout << str1; //-> apple, str1[0]은 a
return 0;
}
728x90
'c++ 기초' 카테고리의 다른 글
6) 구조체 (0) | 2024.12.28 |
---|---|
5) 배열 (0) | 2024.12.27 |
4) const, 데이터형 변환 (0) | 2024.12.27 |
3) bool 기초 (0) | 2024.12.27 |
1)입력, 출력 (0) | 2024.12.27 |