Groups | Search | Server Info | Login | Register


Groups > comp.lang.c.moderated > #426

Re: why I got this answer?

From Jasen Betts <jasen@xnet.co.nz>
Newsgroups comp.lang.c.moderated
Subject Re: why I got this answer?
Date 2013-03-11 18:25 -0500
Organization Dis (not Dat) Organisation
Message-ID <clcm-20130311-0004@plethora.net> (permalink)
References <clcm-20130226-0010@plethora.net>

Show all headers | View raw


On 2013-02-26, 谢成骏 <bbboson@gmail.com> wrote:
> Hi all.
>   I write a small program. But I can't understand the result of it. here is my code:
> -----------------------------------------
> #include <stdio.h>
>
> int* foo(int n)
> {
>     int *p = &n;
>     return p;
> }

n 'evaporates' after you hit the return
the value returned in p points to where n used to be.

> output:
> [999]
> [999]
> Why *p is 999?

999 got put where n used to be.

-- 
⚂⚃ 100% natural
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

why I got this answer? 谢成骏 <bbboson@gmail.com> - 2013-02-26 10:51 -0600
  Re: why I got this answer? Jasen Betts <jasen@xnet.co.nz> - 2013-03-11 18:25 -0500
  Re: why I got this answer? Barry Schwarz <schwarzb@dqel.com> - 2013-03-11 18:25 -0500
  Re: why I got this answer? Thomas Richter <thor@math.tu-berlin.de> - 2013-03-11 18:25 -0500

csiph-web