Home
Add Document
Sign In
Create An Account
Dynamic Memory Allocation
Recommend Documents
No documents
Dynamic Memory Allocation
Download PDF
5 downloads
222 Views
70KB Size
Report
Comment
int main(void). { int* ptr = malloc(sizeof(int)); if (ptr == NULL). { printf("Error -- out of memory.\n"); return 1;. }
Dynamic Memory Allocation
A call to malloc() prototype: void* malloc(size in bytes); example: int* ptr = malloc(sizeof(int) * 10);
Check for NULL! int* ptr = malloc(sizeof(int) * 10); if (ptr == NULL) { printf("Error -- out of memory.\n"); return 1; }
A call to free()
prototype: void free(pointer to heap memory); example: free(ptr);
#include #include int main(void) { int* ptr = malloc(sizeof(int)); if (ptr == NULL) { printf("Error -- out of memory.\n"); return 1; } *ptr = GetInt(); printf("You entered %d.\n", *ptr); free(ptr); }
×
Report "Dynamic Memory Allocation"
Your name
Email
Reason
-Select Reason-
Pornographic
Defamatory
Illegal/Unlawful
Spam
Other Terms Of Service Violation
File a copyright complaint
Description
×
Sign In
Email
Password
Remember me
Forgot password?
Sign In
Our partners will collect data and use cookies for ad personalization and measurement.
Learn how we and our ad partner Google, collect and use data
.
Agree & close