1. Trang chủ
  2. » Giáo Dục - Đào Tạo

06 memory related perils and pitfalls 13 38 tủ tài liệu bách khoa

16 58 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 16
Dung lượng 108,54 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

§  

§  

¢  

§  

§  

§  

¢  

¢  

Trang 2

¢  

¢  

¢  

¢  

¢  

Trang 3

¢  

§  

§  

int val;

scanf(“%d”, val);

Trang 4

/* return y = Ax */

int *matvec(int **A, int *x) {

int *y = (int *)malloc( N * sizeof(int) ); int i, j;

for (i=0; i<N; i++) {

for (j=0; j<N; j++) {

y[i] += A[i][j] * x[j];

}

}

return y;

}

Trang 5

int **p;

p = (int **)malloc( N * sizeof(int) );

for (i=0; i<N; i++) {

p[i] = (int *)malloc( M * sizeof(int) ); }

Trang 6

int **p;

p = (int **)malloc( N * sizeof(int *) );

for (i=0; i<=N; i++) {

p[i] = (int *)malloc( M * sizeof(int) ); }

Trang 7

¢  

§  

char s[8];

int i;

Trang 8

int *search(int *p, int val) {

while (p && *p != val)

p += sizeof(int);

return p;

}

Trang 9

¢  

int *getPacket(int **packets, int *size) { int *packet;

packet = packets[0];

packets[0] = packets[*size - 1];

reorderPackets(packets, *size);

return(packet);

}

Trang 10

int *foo () { int val;

return &val; }

Trang 11

x = (int *)malloc( N * sizeof(int) );

<manipulate x>

free(x);

y = (int *)malloc( M * sizeof(int) ); free(x);

<manipulate y>

Trang 12

x = (int *)malloc( N * sizeof(int) );

<manipulate x>

free(x);

y = (int *)malloc( M * sizeof(int) ); for (i=0; i<M; i++)

y[i] = x[i]++;

Trang 13

foo() {

int *x = (int *)malloc(N*sizeof(int));

return;

}

Trang 14

struct list {

int val;

struct list *next;

};

foo() {

struct list *head =

(struct list *)malloc( sizeof(struct list) ); head->val = 0;

head->next = NULL;

<create and manipulate the rest of the list>

free(head);

return;

}

Trang 15

§  

¢  

§  

§  

§ 

§ 

§ 

§  

§ 

§ 

§ 

Trang 16

§  

¢  

§  

§  

§  

§  

§ 

§ 

§ 

Ngày đăng: 09/11/2019, 07:12

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm