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+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