14, function of the function and the pointer

xiaoxiao2021-03-06  83

----------------

When passing parameters to function, in general, when passing in a non-const, it means that in the function to modify the data in the memory. If it is a pass value, then how to modify this value inside the function, it also affects the value that is not passed, because the pass value is only the memory copy.

what? You said this feature, you understand, ok, let's take a look at the routine below:

Void

Getversion (char * pstr)

{

PSTR = malloc (10);

STRCPY (PSTR, "2.0");

}

Main ()

{

CHAR * VER = NULL;

GetVersion (Ver);

...

...

Free (Ver);

}

I promise that the problem like this is the most important mistake of a novice. The program is in vain through the function getversion to the pointer VER VER VER, but this method does not work at all, the reason is - this is the pass value, not a pointer. You may argue with me, when I divide the pointer? Take a closer look, in fact, what you are passing is that the pointer is actually in the value.

转载请注明原文地址:https://www.9cbs.com/read-107735.html

New Post(0)