Click here to Skip to main content
15,909,437 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: where is the mouse? Pin
Tomasz Sowinski5-Jul-01 23:52
Tomasz Sowinski5-Jul-01 23:52 
GeneralHTTP Post Question Pin
Cabadam5-Jul-01 14:27
Cabadam5-Jul-01 14:27 
Generalifstream question Pin
5-Jul-01 13:10
suss5-Jul-01 13:10 
GeneralRe: ifstream question Pin
Christian Graus5-Jul-01 13:22
protectorChristian Graus5-Jul-01 13:22 
GeneralRe: ifstream question Pin
5-Jul-01 13:25
suss5-Jul-01 13:25 
Generalbasic c/c++ question (const related) Pin
Alex Griffing5-Jul-01 12:12
Alex Griffing5-Jul-01 12:12 
GeneralRe: basic c/c++ question (const related) Pin
5-Jul-01 18:20
suss5-Jul-01 18:20 
GeneralRe: basic c/c++ question (const related) Pin
Malcolm McMahon5-Jul-01 22:35
Malcolm McMahon5-Jul-01 22:35 
When you say
<br />
char anArray[200]<br />


you are saying "Grab me 200 characters worth of local space and call it "anArray". You could them go on to put "Hello World" into it if you wanted, but only by copying it in character by character, for example with:

<br />
strcpy(anArray, "Hello World!");<br />



However because the space for anArray is local it's discarded as soon as your function exits. A pointer returned to it will point to garbage, because that pointer looses it's validity when the routine exits.

The string constant "Hello World" is a different kind of beasty. The string is stored by the compiler in static storage. It's address remains valid for the life of the program.

When you say, for example,

<br />
const char *p = "Hello World";<br />


You are allocating a pointer. A memory location containing the address of that static string. Not a new block of memory containing the string itself (which is why it's ok to do a simple assignment in such a case rather than a more complex copy).


Does that make things clearer?
GeneralProcess Directory Pin
John Uhlenbrock5-Jul-01 11:26
John Uhlenbrock5-Jul-01 11:26 
GeneralRe: Process Directory Pin
Christian Graus5-Jul-01 12:15
protectorChristian Graus5-Jul-01 12:15 
GeneralRe: Process Directory Pin
John Uhlenbrock5-Jul-01 12:18
John Uhlenbrock5-Jul-01 12:18 
GeneralRe: Process Directory Pin
Christian Graus5-Jul-01 12:28
protectorChristian Graus5-Jul-01 12:28 
GeneralRe: Process Directory Pin
John Uhlenbrock5-Jul-01 12:32
John Uhlenbrock5-Jul-01 12:32 
GeneralRe: Process Directory Pin
Tim Deveaux5-Jul-01 13:28
Tim Deveaux5-Jul-01 13:28 
GeneralRe: Process Directory Pin
John Uhlenbrock5-Jul-01 13:30
John Uhlenbrock5-Jul-01 13:30 
GeneralRe: Process Directory Pin
Tim Deveaux5-Jul-01 13:40
Tim Deveaux5-Jul-01 13:40 
GeneralRe: Process Directory Pin
Mike Burston5-Jul-01 14:30
Mike Burston5-Jul-01 14:30 
GeneralRe: Process Directory Pin
Kannan Kalyanaraman5-Jul-01 23:10
Kannan Kalyanaraman5-Jul-01 23:10 
GeneralRe: Process Directory Pin
Mike Burston5-Jul-01 13:36
Mike Burston5-Jul-01 13:36 
GeneralRe: Process Directory Pin
Carlos Antollini5-Jul-01 12:36
Carlos Antollini5-Jul-01 12:36 
GeneralRe: Process Directory Pin
#realJSOP6-Jul-01 4:54
professional#realJSOP6-Jul-01 4:54 
GeneralRe: Everyone. Pin
John Uhlenbrock9-Jul-01 7:05
John Uhlenbrock9-Jul-01 7:05 
GeneralSimulate a carriage return Pin
RobJones5-Jul-01 10:12
RobJones5-Jul-01 10:12 
GeneralRe: Simulate a carriage return Pin
Christian Graus5-Jul-01 12:16
protectorChristian Graus5-Jul-01 12:16 
GeneralRe: Simulate a carriage return Pin
Julien5-Jul-01 13:34
Julien5-Jul-01 13:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.