3.1 Character Array and Strings in C

Character Array: -

  • Character array is an array used to store a collection of characters.
  • Each element of the array can store one character.
  • It can store multiple characters in consecutive memory locations.
  • A character array can store letters, numbers, special symbols, or a combination of them.
  • Character Array index starts from 0 to n-1.


Character array declaration: -

Syntax: -

Example: -

Character array initialization: -

Syntax: -

Example: -

Program: -


Output: -


Strings: -

  • String is a sequence of characters that ends with a special character called the 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 index starts from 0 to n-1.

 

String Declaration: -

Syntax: -


Example: -


String Initialization: -

Syntax: -


Example: -


Program: -


Output: -




Popular posts from this blog

2.1 Control statements in C programming (sequential & conditional)

2.4 Arrays in c programming

3.5 Parameter passing techniques in C