30.10.2014 Views

o_195h4n6al16jb186b1b2qs7fgssa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

free<br />

Description: Frees memory.<br />

Include: <br />

Prototype: void free(void *ptr);<br />

Argument: ptr points to memory to be freed<br />

Remarks: Frees memory previously allocated with calloc, malloc, or<br />

realloc. If freeis used on space that has already been deallocated<br />

(by a previous call to freeor by realloc) or on space not allocated<br />

with calloc, malloc, or realloc, the behavior is undefined.<br />

Example: #include /* forprintf, sizeof, */<br />

/* NULL */<br />

#include /* for malloc, free */<br />

int main(void)<br />

{<br />

long *i;<br />

if ((i = (long *)malloc(50 * sizeof(long))) ==<br />

NULL)<br />

printf("Cannot allocate memory\n");<br />

else<br />

{<br />

printf("Memory allocated\n");<br />

free(i);<br />

printf("Memory freed\n");<br />

}<br />

}<br />

Output:<br />

Memory allocated<br />

Memory freed<br />

getenv<br />

Description: Get a value for an environment variable.<br />

Include: <br />

Prototype: char *getenv(const char *name);<br />

Argument: name name of environment variable<br />

Return Value: Returns a pointer to the value of the environment variable if<br />

successful;<br />

otherwise, returns a null pointer.<br />

Remarks: This function must be customized to be used as described (see<br />

pic30-libs). By default there are no entries in the environment list<br />

for getenvto find.<br />

z = ldiv (x, y);<br />

printf ("thương là% ld và"<br />

"Còn lại là% ld \ n \ n",<br />

z.quot, z.rem);<br />

}<br />

dsPIC<br />

®<br />

Thư viện Công cụ Ngôn ngữ<br />

DS51456B trang 284<br />

Đầu ra:<br />

Đối với ldiv (7, 3)<br />

Các thương là 2 và phần còn lại là 1<br />

Đối với ldiv (7, -3)<br />

Thương số là -2 và phần còn lại là 1<br />

Đối với ldiv (-5, 3)<br />

Thương số là -1 và phần còn lại là -2<br />

Đối với ldiv (7, 7)<br />

Các thương là 1 và phần còn lại là 0<br />

Đối với ldiv (7, 0)<br />

Thương số là -1 và phần còn lại là 7<br />

Giải thích:<br />

2004 Microchip Technology Inc<br />

Trong ví dụ cuối (ldiv (7,0)) mẫu số là số không, hành vi<br />

là không xác định.<br />

malloc<br />

Mô tả: Phân bổ bộ nhớ.<br />

Bao gồm:<br />

Nguyên mẫu: void * malloc (size_t size);<br />

Đối số: số kích thước của ký tự để phân bổ<br />

Quay trở lại giá trị: Trả về một con trỏ đến không gian được phân bổ nếu thành<br />

công; nếu không,<br />

trả về một con trỏ null.<br />

Bình luận: mallocdoes không khởi tạo bộ nhớ nó sẽ trả về.<br />

Ví dụ: # include / * Cho printf, sizeof, * /<br />

/ * NULL * /<br />

# include / * Cho malloc, * miễn phí /<br />

int main (void)<br />

{<br />

dài * i;<br />

if ((i = (long *) malloc (50 * sizeof (long))) ==<br />

NULL)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!