[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

c malloc osv.



Hejsa Liste,

Igen, jeg er ny i c, men har fra tid til anden lavet noget c++.

Jeg er kommet noget i tvivl om hvordan det er med c og hukommelses håndtering, og hvornår det er nødvendigt at bruge malloc/free osv.

Eks 1.
char* hejsa = (char *) malloc( 6 );
strcpy( hejsa, "Hejsa" );
printf(hejsa);
free( hejsa );

Eks 2.
char* hejsa2 = "Hejsa2";
printf( hejsa2 );

Eks 3.
char hejsa3[7] = "Hejsa3";
printf(hejsa3);


Hvad er den store forskel her? Bort set fra at eks2 kun har 50% så mange linjer, plus jeg ikke har sagt hvor stort et område jeg skal bruge.
Eks 3 er lidt åbenlys at den skiller sig ud, men jeg er meget i tvivl om hvad der er best pracsis her.


./Morten

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2007-12-01, 02:01 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *