How come the following c++ code generate nonsense character output?
#include <iostream.h>
char* mmString(int mm) {
char mmList[12][20] =
{ "January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December " };
return(mmList[mm-1]);
}
int main() {
int month;
for (month=1; month<13; month++) {
cout << mmString(month) << endl;
}
return 0;
}
The actual out put is 12 lines of nonsense character rather than the name of 12 months.
Why? Is it because I haven't initialize the string properly? If that is really the case, I cannot figure the rationale behind.



LinkBack URL
About LinkBacks



