c - Does malloc allocate memory from 0 to positive infinity? -


I wrote a test program that the address of P1 would be less than P2, but when I compiled the code, address P 2 has to be low (P1 is greater than P8 8). I also rumored that 2 adjacent memory blocks will be automatically combined. Does any part play in the following code?

  Zero main () {char * p1, * p2; P1 = malloc (4); P2 = malloc (5); P1 = "yes"; P2 = "goog"; Printf ("p1 =% d, and p2 =% d \ n", p1, p2); }  

You are not printing the addresses sent from the malloc, but the string The address literally (which are static allocated) If you want to fill the blocks, use strcpy; Doing so is not necessary to print addresses, though.

Also, use% p to print indicators.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -