Chapter 6Strings

DOI: 10.1201/9781003257981-6

C does not have a specific data type for strings. Instead, in C programs, strings are arrays of characters (char). A string can include alphabet characters, digits, spaces, and symbols. Strings can be created by putting characters between double quotations. For example,

  • “Hello”

  • “The C language”

  • “write 2 programs”

  • “symbols $%# can be part of a string”

The examples are string constants: their data cannot be edited. Often string variables are preferable to store strings whose values may change. For example, a program may ask a user to enter a name. The programmer does not know the user's name in advance, and thus cannot use any constant. From the program's point of view, the name is a string variable ...

Get Intermediate C Programming, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.