3.1 Character Array and Strings in C

 Character Array: -

  • Character array is an array that can store a sequence of characters.
  • Each element of the array can store one character.
  • Array can store multiple characters in consecutive memory locations.
  • Character arrays are commonly used to store strings, but they can also hold individual characters not forming a string.
  • If used as a string, the last element must be the null character '\0' to indicate the end of the string.

 Character array declaration: -

 Syntax: -

Example: -

Character array initialization: -

Syntax: -



Example: -

Program: -


output: -


Strings: -

  • String is a collection of characters terminated by a null character (\0).
  • Strings are used to store text like names, messages, or any series of characters.
  • Internally, a string is represented as an array of characters.
  • The null character \0 indicates the end of the string. Without it, C won't know where the string ends.
  • String can store multiple characters in consecutive memory locations

 String Declaration: -

Syntax: -

Example: -

String Initialization: -

Syntax: -

Example: -

program: -

output: -


Popular posts from this blog

operators in c programming

2.4 Arrays in c programming