Difference between revisions of "Malloc"
From Teknologisk videncenter
m (added Category:C using HotCat) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <source lang= | + | <source lang=c> |
#include <stdio.h> | #include <stdio.h> | ||
#include <malloc.h> | #include <malloc.h> | ||
Line 23: | Line 23: | ||
pointer[3] = 0; | pointer[3] = 0; | ||
leg( pointer ); | leg( pointer ); | ||
+ | free( pointer ); | ||
return(0); | return(0); | ||
} | } | ||
+ | ~ | ||
+ | |||
</source> | </source> | ||
[[Category:C]] | [[Category:C]] |
Latest revision as of 12:20, 22 August 2016
#include <stdio.h>
#include <malloc.h>
leg( char *array ) {
int i;
while( array[i] != 0) {
putchar(array[i]);
i++;
}
}
int main( void ) {
char *pointer;
int i;
pointer = (char *) malloc( sizeof(char) * 4);
pointer[0] = 'H';
pointer[1] = 'e';
pointer[2] = 'j';
pointer[3] = 0;
leg( pointer );
free( pointer );
return(0);
}
~