CS 162 Lecture Notes - Lecture 22: Memory Management, C Dynamic Memory Allocation, Memory Address

38 views1 pages
CS 162 Lecture 22 Introduction to C (Short Lecture, Group Activity)
C vs. C++
o & means address of always
o All libraries that will be included end in .h
o Variables must be declared at the top of the function
o “tructs ust hae the ord struct i frot of the heeer declared uless it
has been typedef
o File I/O works off a file pointer
o Compile with gcc
C vs. C++: Input/Output
o Get input via scanf()
Takes a format specifier and an address to store input into
Ep: scaf%d, &_u;
& correspods to address
o Produce output using printf()
Prints a string which may have format specifiers
If format specifiers are provided, the variables should be produced in the
order of appearance
Ep: pritfDa: %d Moth: %s Year: %d \, da, oth, ear;
C vs. C++ Dynamic Memory
o Use malloc()
o Takes the size of memory in bytes
o Returns a memory address as a void*
o Exp: int* array = (int*) malloc(sizeof(int)*5);
o Use free() to delete
Name of the dynamic memory in parentheses
Free(array)
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

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