0
0
C++programming~15 mins

Character arrays in C++ - Mini Project: Build & Apply

Choose your learning style9 modes available
Character arrays
📖 Scenario: You are working on a simple program that stores and manipulates a name using character arrays in C++. This is like writing a name on a piece of paper where each letter is stored in order.
🎯 Goal: Build a program that creates a character array with a name, counts how many letters it has, and then prints the name and its length.
📋 What You'll Learn
Create a character array with the exact name "Alice"
Create an integer variable to store the length of the name
Use a loop to count the number of characters in the array until the end
Print the name and the length
💡 Why This Matters
🌍 Real World
Character arrays are used in many programs to store and manipulate text, especially in older or low-level C++ code.
💼 Career
Understanding character arrays helps in jobs involving embedded systems, game development, or any C++ programming where direct memory control is important.
Progress0 / 4 steps
1
Create a character array
Create a character array called name and set it to the exact string "Alice".
C++
Need a hint?

Use double quotes to set the string inside the character array.

2
Create a length variable
Create an integer variable called length and set it to 0.
C++
Need a hint?

This variable will count how many letters are in the name.

3
Count characters in the array
Use a for loop with an integer i starting at 0 to count characters in name until you find the null character '\0'. Increase length by 1 for each character.
C++
Need a hint?

Remember, character arrays end with a special '\0' character.

4
Print the name and length
Use std::cout to print the text Name: followed by name, then print Length: followed by length. Each on its own line.
C++
Need a hint?

Use std::cout with << to print text and variables.