String
◀ STL Container Class Set▶ Character Array in C Amazon
Once upon a time, Tailand and Chiland were ready to launch a full-scale projectile war against each other. Each of them was using only one bomb launcher in the war, but their implementations were different. Tailand was using a character array to manage the launcher, while Chiland, being more clever, was using a string to manage their bomber.
The war thus began. In the beginning the war was a tossup, but at one moment Chiland decided to do something different.
“Insert two more A-bombs right after the bomb indexed at the 6th place in the launcher. Replace the second to the last bomb with an H-Bomb. Switch the order of all fission bombs with that of fusion bombs.”
“Well do”
Tailand became agitated.
“What are we going to do? We cannot insert or append any of our bombs in the launcher once we initialize them. What in God’s name are we going to do?”
Bombing from Chiland kept on going. They were able to dynamically change the types of bombs to their hearts’ content. Eventually Tailand sank deep in the ocean and never surfaced again.
Now you should know clearly why you should use a string instead of a character array.
The above joke does not make much sense because
string is a class provided by the C++ STL whose underlying implementation is actually a character array. The string class provides common string manipulation functions so that managing a
char array is less of a hassle. But I like the joke so I am keeping it.
Let’s explore the string class so that you can take full advantage of its functions in your programming career!
◀ STL Container Class Set▶ Character Array in C