MAT 21B Lecture 16: Lecture 16
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
beigecamel74 and 41 others unlocked
83
MAT 21B Full Course Notes
Verified Note
83 documents