Subj : Re: Local character strings To : borland.public.cpp.borlandcpp From : maeder Date : Mon Sep 26 2005 07:26 pm "Ray Sittig" writes: > It's now clear that char* my_variable != char my_variable[]. > There's an exam question here... > Modified program below. Still undefined behavior. > #include > #include > > int main(void); > void PrintText(int version); > > int main() > { > PrintText(2); > PrintText(1); > PrintText(2); > printf( "\nPlease press '1' to continue.\n"); > while (true) > { > if (getche() == '1') > break; > } > return 0; > } > > void PrintText(int version) > { > // array not the same as a pointer > // array on stack, initialized with each call > // pointer to string literal initialized once globally ? > char MyTextArray[] = "2 Array[]"; > char* MyTextPointer = "2 Pointer"; As I tried to make clear in my last post, you shouldn't do this in new code. The line only compiles because of a deprecated feature. Do this instead: char const * MyTextPointer = "2 Pointer"; .... > if (version == 1) > MyTextArray[0] = MyTextPointer[0] = '1'; .... and the compiler will help you avoiding this kind of undefined behavior. .