MAT 21B Lecture 16: Lecture 16
![](https://new-preview-html.oneclass.com/OoAwBLpx4XaZjRRp5e1Bj1rVR07geYJ8/bg1.png)
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
![MAT 21B Full Course Notes](https://new-docs-thumbs.oneclass.com/doc_thumbnails/list_view/2365737-class-notes-us-uc-davis-mat-21b-lecture13.jpg)
83
MAT 21B Full Course Notes
Verified Note
83 documents