char
배열의 배열을 반환하는 중입니다. 배열을 성공적으로 만들 수는 있지만 분명히 잘못 반환하고 있습니다.함수에서 char 포인터 배열 반환 (C++)
내 구문이 해제되어 있습니까? 아니면 내가 간과하고있는 다른 오류가 있습니까? 여기
은 전체 기능이 여기에// prototype
char * testFunc();
// Function
char * testFunc() {
char* ptrArray[2];
return(*ptrArray);
}
// Assignment in main()
int main {
char * res = testFunc();
}
는 "이라고도 자동 저장 (에 할당 된 전체 코드 객체를 반환
#include <iostream>
using std::cout;
// prototype
char * testFunc();
int main() {
short i, j;
char * res = testFunc();
for (i=0; i < 2; i++)
cout <<"This is res[" << i << "] : " << res[i] <<"\n";
return(0);
}
char * testFunc() {
char word1[] = "one";
char word2[] = "two";
// create an array of char*
char* ptrArray[2];
ptrArray[0] = word1;
ptrArray[1] = word2;
for (int i=0; i<2; i++)
cout <<"This is ptrArray[" << i << "] : " << ptrArray[i] <<"\n";
return(*ptrArray);
}
http://stackoverflow.com/questions/3716595/c-returning-multidimension-array-from-function – yuan