Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

The GNU C Programming Tutorial - Conventions and declarations

Node:Conventions and declarations, Next:, Previous:Strings, Up:Strings



Conventions and declarations

Do not confuse strings in C with individual characters. By convention, individual characters are enclosed in single quotes, like this: 'a', and have the variable type char. On the other hand, string values are enclosed in double quotes, like this: "abcdefg". String variables are either arrays of type char or have the type "pointer to char", that is, char *.

Conceptually, a string is an array of characters (type char). In C, string variables can theoretically be of any length, unlike languages such as Pascal where strings hold a maximum of 255 characters. However, the length of the string value is determined by the position of the first null character ('/0') in the string. Even though a string variable might be 32,000 characters long, or longer, if the null character first appears at position 5 in the character array, the string value is considered to be of length 5 (and contains the characters in positions 0 through 4, in sequence). You will rarely need to consider this end marker, as most functions in C's string library add it or remove it automatically.

 
 
  Published under free license. Design by Interspire