CIS 1500 Lecture Notes - Lecture 22: C Dynamic Memory Allocation

39 views2 pages

Document Summary

Announcements: assignment 4 descriptions updated, there are no labs next week. Study sessions will be available during the first week of exams. Pointers double myvar; // lets say this variable occupies address: 0x1 double * dptr; // lets say this pointer occupies address: 0xa1f myvar = 10. 00; dptr = 10. 00; // this will cause a seg. fault! Points can only hold addresses dptr = &myvar; // this works wonderfully! Now dptr points to 10. 00 printf(%lf, dptr); // again this is bad! dptr is not a long float, it is a pointer printf(%lf, *dptr); // this works fine, the pointer is properly dereferenced. *dptr = 29. 6; // now myvar is equal to 29. 6, since that"s what dptr references to. Example - reversing a string reversestring returns a new string that is the reverse of the input string, the new string is allocated on the heap. Note that a char * is like a character array, but is not the same thing.

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