C Programming String – Summary



This tutorial is overall summary of C Programming String concept. In this tutorial we are listing out some of the key concepts related to C Programming Strings.

Introduction to C Programming String :

Like Java, we don’t have C Programming String data type. In C we have to use different approach to store the string. We are creating array of character to creating string. Suppose we have to accept the name of the person then n characters are collected together and string or character array is created.

C Programming String : Summary

A. Character array

C programming string is also called as Character Array. String is nothing but the collection of the individual array elements or characters stored at contiguous memory locations

'C','4','L','E','A','R','N'

B. Double quotes

String is enclosed within Double quotes

"Pritesh" is a example of String

If string contains the double quote as part of string then we can use escape character to keep double quote as a part of string.

"Prit\"esh" is a example of String

Re-commanded Example : Multi-line Printf statement

C. Memory

Each Character Occupy 1 byte of Memory

Size of "Pritesh" = Size of 'P' +
                  = Size of 'R' +
                  = Size of 'I' +
                  = Size of 'T' +
                  = Size of 'E' +
                  = Size of 'S' +
                  = Size of 'H';

Size of "Pritesh" = 7 BYTES

Each Character is stored in consecutive memory location

Address of 'P' = 2000
Address of 'R' = 2001
Address of 'I' = 2002
Address of 'T' = 2003
Address of 'E' = 2004
Address of 'S' = 2005
Address of 'H' = 2006

D. NULL Character

String always Terminated with NULL Character (‘/0′)

char name[10] = {'P','R','I','T','E','S','H','\0'}

NULL Character is having ASCII value 0

ASCII Value of '\0' = 0

As String is nothing but an array , so it is Possible to Access Individual Character

name[10] = "Pritesh";

It is possible to access individual character

name[0] = 'P';
name[1] = 'r';
name[2] = 'i';
name[3] = 't';
name[4] = 'e';
name[5] = 's';
name[6] = 'h';
name[7] = '\0';