CS136 Lecture Notes - Lecture 17: Scanf Format String, String Literal, Null Character

91 views4 pages

Document Summary

Strings: no built-in c string type, array of characters, terminated by a null character (null terminator) ==> \0". Char my_string [4] = { c", a", "t", \0"}: if no null terminator detected, keep going until get some random garbage left in the system, assume to be valid string, dont need to pass length, should assert. Strings initialization: char arrays can be initialized by double quote ( ) Char a[] = { c", a", "t", \0"}; Char c[4] = { c", a", "t"}; > last position for null terminator. Char c[3] = { c", a", "t"}; > this is character array, not string, no place for null terminator. Char f[] = cat ; -> is string, array of length 4: null terminator is value 0 (false) > while s[i] { } // not the null terminator. Lexicographical order: compare ascii value, character by character. String i/o: %s, scanf ( %s , )

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