MAT 21B Lecture 16: Lecture 16

49 views2 pages
School
Department
Course
Professor
Lecture 16
See powerpoint for code lines
String basics
Array vs string
- Last byte of array of character must be 0 to be considered as a string
- Placeholder %s for printing a string
Initialization
- String must be one more than the number of characters, for the ending null character
- String can be smaller than array
- String cannot be bigger tha narray
- See powerpoint for example
Input and output
- String variables passed to scanf ( ) is a memory address
o Array always decay into pointers
o No need for &
- Scan f( ) comes with some specificities and limitations around strings
- Does not know the maximum size of the string, possibility of overflowing trigger bad
side effects
Function argument
- Strings are received as parameters by pointers
- Functions don’t know the size of string
o Unless its provided
- Pitfall: see comparison on powerpoint
String length
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 2 pages and 3 million more documents.

Already have an account? Log in
beigecamel74 and 41 others unlocked
MAT 21B Full Course Notes
83
MAT 21B Full Course Notes
Verified Note
83 documents

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