problem with the code

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

    #16
    Re: problem with the code

    jacob navia wrote:
    Richard Heathfield wrote:
    >raashid bhatt said:
    >>
    >>On Aug 24, 11:22 pm, ramu <ramu....@gmail .comwrote:
    >>>Hi,
    >>>Is there any problem with the following code?
    >>>>
    >>>Regards
    >>>>
    >>>char *func()
    >>>{
    >>>char c;
    >>>return (&c);}
    >>>>
    >>>#include<std io.h>
    >>>int main()
    >>>{
    >>>char *ch;
    >>>ch = func();
    >>>*ch = 'A';
    >>>pritnf("%c", *ch);
    >>>>
    >>>}
    >>as u see c is a local stack variable as soon a function returns the
    >>its stack is cleared and it goes out of scope!
    >>
    >Pretty much, yes. We can reduce the machine-specific nature of the
    >reply by re-wording to something like "c has automatic scope, and so
    >it is destroyed when control returns from func to its caller".
    >>
    >
    I just can't understand why everybody competes in the
    game:
    >
    Who does better ramu's homework?
    >
    You are NOT helping him.
    >
    The question is on topic and the answers are subject to review.
    You passed up a chance to correct Richard Heathfield.
    There is no such thing as "automatic scope".

    --
    pete

    Comment

    • Richard Heathfield

      #17
      Re: problem with the code

      pete said:
      jacob navia wrote:
      <snip>
      >Who does better ramu's homework?
      >>
      >You are NOT helping him.
      >
      The question is on topic and the answers are subject to review.
      You passed up a chance to correct Richard Heathfield.
      And it is now too late, because you beat him to it.
      There is no such thing as "automatic scope".
      Oh, give it time, give it time...

      --
      Richard Heathfield <http://www.cpax.org.uk >
      Email: -http://www. +rjh@
      Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
      "Usenet is a strange place" - dmr 29 July 1999

      Comment

      • Richard

        #18
        Re: problem with the code

        jacob navia <jacob@nospam.c omwrites:
        Richard Heathfield wrote:
        >raashid bhatt said:
        >>
        >>On Aug 24, 11:22 pm, ramu <ramu....@gmail .comwrote:
        >>>Hi,
        >>>Is there any problem with the following code?
        >>>>
        >>>Regards
        >>>>
        >>>char *func()
        >>>{
        >>>char c;
        >>>return (&c);}
        >>>>
        >>>#include<std io.h>
        >>>int main()
        >>>{
        >>>char *ch;
        >>>ch = func();
        >>>*ch = 'A';
        >>>pritnf("%c", *ch);
        >>>>
        >>>}
        >>as u see c is a local stack variable as soon a function returns the
        >>its stack is cleared and it goes out of scope!
        >>
        >Pretty much, yes. We can reduce the machine-specific nature of the
        >reply by re-wording to something like "c has automatic scope, and so
        >it is destroyed when control returns from func to its caller".
        >>
        >
        I just can't understand why everybody competes in the
        game:
        >
        Who does better ramu's homework?
        >
        You are NOT helping him.
        You are assuming it is homework.

        And I hate tell you , but coming out here and finding the right answer
        IS doing ones homework.

        Give the answer and explain it. He wont find it by banging sticks
        together.

        Comment

        • August Karlstrom

          #19
          Re: problem with the code

          ramu wrote:
          Hi,
          Is there any problem with the following code?
          >
          Regards
          >
          char *func()
          {
          char c;
          return (&c);
          }
          #include<stdio. h>
          int main()
          {
          char *ch;
          ch = func();
          *ch = 'A';
          pritnf("%c",*ch );
          }
          Well, what do gcc with options `-ansi', `-pedantic' and `-Wall' say?


          August

          Comment

          Working...