/*
선언된 배열의 개수 구하기
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
int iCnt = 0;
// int 배열
const int iArr[] = {1,2,3,4,5};
iCnt = sizeof(iArr)/sizeof(int);
cout << "iArr 배열 사이즈 = " << iCnt << endl;
// double 배열
const double dArr[] = {12.25, 25.15, 45.3};
iCnt = sizeof(dArr)/sizeof(double);
cout << "dArr 배열 사이즈 = " << iCnt << endl;
// char* 배열
const char* szArr[] = {"사과","배","바나나"};
iCnt = sizeof(szArr)/sizeof(char*);
cout << "szArr 배열 사이즈 = " << iCnt << endl;
// string 배열
const string strArr[] = {"보리","옥수수","감자","고구마"};
iCnt = sizeof(strArr)/sizeof(string);
cout << "strArr 배열 사이즈 = " << iCnt << endl;
return 0;
}
'Test Code > C++' 카테고리의 다른 글
[WinApi] GetCurrentDirectory 현재 경로 가져오기 (0) | 2013.12.27 |
---|---|
[WinApi] Ini 파일 읽고 쓰기 (0) | 2013.12.27 |
[STL] algorithm for_each 예제 (0) | 2013.12.27 |
c++ time.h (0) | 2013.12.24 |
c++ 문자를 숫자로 숫자를 문자로 (0) | 2013.12.24 |