출처 : http://acpi.tistory.com/16



/*

선언된 배열의 개수 구하기

*/


#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;

}










Posted by motolies
,