Lecture 8 b Strings BJ Furman 15 OCT

Lecture 8 b: Strings BJ Furman 15 OCT 2012

Overview n Strings ¨ ¨ ¨ What is a string? How do you declare and initialize an string? How can you use a string? String Examples n String Practice n

Learning Objectives n Explain what a string is ¨ Explain the connection between arrays and strings n Declare and initialize a string n Use a string in a program

What is a String? n Last time we looked at arrays ¨ data structures that contain a collection of data objects of the same data type n. A string is an array of characters terminated by the NUL character ¨ ¨ Data type is array of characters The NUL character is a character with a numeric value of zero n n String ¨ constant (or string literal) Any series of characters enclosed in double quotes n n String ¨ ¨ In C, it is represented by the escape sequence, (NUL) Ex. "Hello world" example program stores a string constant stores individual elements n n note: character constants note: terminate with '