ECS 30 Lecture Notes - Lecture 14: Whitespace Character, Null Character, Memory Address

29 views4 pages
Wednesday, 2 May 2018
ECS 030 Lecture 14
Strings
Arrays vs Strings
-Think of strings as a quote
can put anything in in it (any
character)
can only occur as an
element of an array
-Last byte of array of characters
must be 0 to be considered as
a string
-Placeholder %s for printing a
string
Initialisation
-String must be one
"more" than the
number of characters,
for the ending null
character:
-Strings can be smaller than an array, but they cannot be bigger than an array
if the “quote” has 21 characters, and it’s placed at index 20, the last index in the
array, error will occur
1
Unlock document

This preview shows page 1 of the document.
Unlock all 4 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Think of strings as a quote: can put anything in in it (any character, can only occur as an element of an array. Last byte of array of characters must be 0 to be considered as a string. more than the number of characters, for the ending null character: Strings can be smaller than an array, but they cannot be bigger than an array: if the quote has 21 characters, and it"s placed at index 20, the last index in the array, error will occur. String variable passed to scanf() is a memory address: arrays always decay into pointers, no need for & Scanf() comes with some speci cities and limitations around strings: has limitations. Skips leading whitespace before the input (whitespace, tabs, newlines) Stops matching a string at the rst whitespace character: if you want to input more separate words into a string, you will need to use multiple scanf statements.

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