CIS 2500 Lecture Notes - Lecture 12: C Dynamic Memory Allocation, Data Corruption, Null Pointer

26 views5 pages

Document Summary

Iptr[i][j] = i + j; free(iptr[i][j]); for(j=0; j<15; j++) { free(iptr[i]); iptr[i] = malloc(sizeof(int)*15); for(j=0; j<15l j++) { printf(n); Array of pointers require a loop of free()"s int **iptr; int i, j; iptr = malloc(sizeof(int*)*10); for(i=0; i<10; i++) { for (i=0; i<10; i++) { for(i=0; i<10; i++) { free(iptr); Reading or writing past the end of an array. In c nothing stops you from using an index to an array that is larger than the size of array. No apparent problem except data corruption, program crash. Writing to the executable part will have unpredictable results. Stay within the limit when dynamically allocating arrays. //the string is contained in both the pointer and pointer name for(i=0; i<4; i++) { //when you initialize the pointer to point to the variable, it is only pointing to the start of the variable. //when you ptr++; it allows the pointer to advance to the next character.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents