Step by step

My diary

...

Search

breakinformation. Powered by Blogger.

2018년 9월 24일 월요일

malloc, calloc


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
    
    int *pointerNumber = malloc (sizeof (int* 10);
    
    pointerNumber[0= 10;
    pointerNumber[9= 20;
    
    printf(" == malloc ==\n");
    printf("%d\n", pointerNumber[0]);
    printf("%d\n", pointerNumber[5]);
    printf("%d\n", pointerNumber[9]);
        
    free(pointerNumber);
    
    int *pointerNumber2 = calloc (10sizeof(int));
    
    pointerNumber2[0= 10;
    pointerNumber2[9= 20;
    
    printf("\n == calloc ==");
    printf("\n%d\n", pointerNumber2[0]);
    printf("%d\n", pointerNumber2[5]);
    printf("%d\n", pointerNumber2[9]);
        
    free(pointerNumber2);
        
    return 0;
}
cs

0 개의 댓글:

댓글 쓰기