Character Array
Lesson 6 of 26 in Coddy's Arrays in C++ course.
These arrays are particularly used to store characters. if we want to store a word then character arrays are used.
to declare a character array we set the size of the array at least by adding one to the number of words that it has.
For example, the word "Arya" has 4 letters to store this individually as letters in the array, we declare an array of characters of size 4+1 that is of size 5.
char name[5];
To be on the safe side we always declare an array of greater numbers like of size100 which will work in any condition.
Why character arrays are used?
It is used to store words. that one extra space that we have taken from the memory is for declaring NULL.
NULL represents the end of the word and is represented as '\0'
We can use a character array as an individual data type also for taking input and output
char str[100];
cin>>str;
cout<<str;If we want to access the individual character then also we can do it considering 0-based indexing.
cout<<str[2];Challenge
Input a word in form of a character array and print its individual characters separated by space using a while loop.
Try it yourself
#include<iostream>
using namespace std;
int main(){
//Write your code here
return 0;
}