any wrong with this piece of code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • YYweii

    #1

    any wrong with this piece of code?

    Hi all

    my teacher say there is something wrong with this piece of code, but i
    can't figure it out, help !

    void GetMemory(char *p, int num)
    {
    p = new char[num];
    }

    int main()
    {
    char *p;
    GetMemory(p, 100);
    ...
    ...
    }
  • Ian Collins

    #2
    Re: any wrong with this piece of code?

    YYweii wrote:
    Hi all
    >
    my teacher say there is something wrong with this piece of code, but i
    can't figure it out, help !
    >
    void GetMemory(char *p, int num)
    {
    p = new char[num];
    Think very carefully about what this line does. What does changing p do?

    --
    Ian Collins.

    Comment

    • YYweii

      #3
      Re: any wrong with this piece of code?

      I see. Many thanks!

      Comment

      Working...