mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-04-01 17:53:26 +08:00
update
This commit is contained in:
19
codingStyleIdioms/3_RAII/c_example.cpp
Normal file
19
codingStyleIdioms/3_RAII/c_example.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by light on 19-12-12.
|
||||
//
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
int main() {
|
||||
char *str = (char *) malloc(7);
|
||||
strcpy(str, "toptal");
|
||||
printf("char array = \"%s\" @ %u\n", str, str);
|
||||
|
||||
str = (char *) realloc(str, 11);
|
||||
strcat(str, ".com");
|
||||
printf("char array = \"%s\" @ %u\n", str, str);
|
||||
|
||||
free(str);
|
||||
|
||||
return(0);
|
||||
}
|
||||
Reference in New Issue
Block a user