Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Code

Name: Anonymous 2012-02-03 7:55

Can someone please tell me what this code does?
void f(int *x)
{
   x=(int*)malloc(sizeof(int));
   *x=12;
}
int main(){
    int v=10;
    f(&v);
    printf("%d\n",v);
    return 0;
}
It return 10

Name: Anonymous 2012-02-03 9:02

you pass a reference to a symbol v that is known as x in another scope, then you modify the value of x (but not the value referenced by v), so naturally v stills references to 10

Name: Anonymous 2012-02-03 9:05

basically your use of malloc is retarded since local symbols are already allocated on the stack and x needs not be persistant

Name: Anonymous 2012-02-03 10:47

it leaks memory

Name: Anonymous 2013-09-01 21:05



           _!ゝ、.,_,. -- 、___,,.. -‐─ァ       (  )
          Σ_ _,..'ニi二7ニ、..,,___  _フ        ( )
          ,. '"´:::::::::::::::::::::::::::::::::::`ヽ、7          ノ7ミヽ/|
        _/_;;::::-──-- 、:;___:::::::::::::::::::':,      ( ) //ミミ!/ミヽ、 ( )
       r'ン-‐'' "´ ̄ ̄``"''ー 、ヽ:;:::::::::::::::',        ノ/ミ ミ/ミミヽ/
     / /            `ヽヽ:_::::::::|       〈iミ ミ/ミヽミン
    /  ,/   / /   i    ,      `ヾヽ:!   |/|   \7/ミヽミ/
    ,'  /7   ,ハ ‐|、 /|  /|   、  ヽ. ヽ.)   /!. ト、   /,へミヽノ
    i /-|  /ァ'f"'ヽ/ | / .|    ,!   ',  ', //  i`'ァ__/// `''´
    レ'へ|  /〈 ト、 7` |/   |-‐-/|    i i i ヽ.く_/,!-'、-'、ヽ.
       |/7,, ` `''´     ,.'--=、 !  / | ',  | | ,.'-‐、 ヽ  !
     /  ハ.    '          `,' ,.イヽ,|  ヽ.ノ / ! ,r、     ,'>
    /  / へ.   l7 ̄ `ヽ  ""///ヽ、.!__,ハ i / |7'ゝ、  ,.イヽ.
    ´ ̄7 /.>iヽ.,ヽ、___ン   /´ /_>-''"'- !、  !'  >、_`ン  ハ
       |/\.|`7'´i>-‐r___'7´  ./'"      ,ヽ.  ', 、.,____,ン' `',
        く /  ,ハヘ、____,.ィ|/|,.イ      _r'7´`''ーヘ  !    i
         レヘ.   i::}>O<{::::::::::!      、_//ヽ   /!       |
           kニヘ/::::::';::::::::::::::::::ゝ.     | |     ,'        |
          ',   i';::::::ヽ、::::::/|::::ヽ、.,____,.!ヘ    !       ,'
          .i    ':;::::::}>oン::::::::::::::::ヽ_!__>、.,_        /
           |    iヽ:::::';:::::::::`ヽ、:;__|^7ァ /、    `ヽ、.,_____/
            i     ト、;:_::::::::::::::::::_;:O'イ:::::/\.
          ,'      |::::::/::`T''"´:::::';::::::::メ::::::::::ヽ.
          /       .!::/::::::::!:::::::::::::::'}>o<{::::::::::':,、
        rン、.,___     ,!ン'::::::::::::::::::::::::::::i/:::::::::::::::::::',ヽ.
        /i´  r`ヽ、__」:::::::::::i:::::::::::::::/::::::::::::::::: i::::::::i:::::'

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List