CPS 125 Lecture Notes - Lecture 1: Memory Management, Scanf Format String, C Dynamic Memory Allocation

92 views2 pages

Document Summary

#include int main(void) int i; int n; int sum = 0; int *ptr; Integer i" has 4 bytes and speci c address. Integer n" has 4 bytes and speci c address. 0 stored in memory location for sum ptr is a pointer variable to an integer. stores adress (2 bytes) prtinf( enter size of array\n ); scanf( %d ,&n); ptr=(int*)calloc(n,sizeof(int)); memory locations. 2 int parameters; size, and sizeof each of those. In stdio. h header le, displays on output device. Using calloc function, you can create that many memory locations going to be created. the size of. Ask if there is enough memory, b/c heap memory these memory locations will be 4 bytes, because the data type is integer. if(ptr=null) is limited. Ask for big numbers. printf( error, not enough memory, no memory locations were allocated\n ); exit(0); enough memory locations, program exits.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents