Today, we will learn C++ Array Assignment. We can assign multiple values to C++ Arrays. There are many ways you can initialize a C++ array. You can create different datatypes of arrays in C++ e.g. string, int, etc are the two most common types of C++ arrays that are commonly used. Today, we will see how to initialize and assign values to C++ arrays. Let’s start.
Declaring Empty C++ Array
We can declare an empty array in C++ using square brackets and specifying the number of items.
string city[5];
int id[6];
Declaring and C++ Array Assignment
We can declare and initialize a C++ Array at the same time. To initialize a C++ Array while declaring, we can use curly brackets and then values inside curly brackets.
string city[5] = {"Agra", "Delhi", "Noida", "Gurgaon", "Banglore"};
Accessing the elements of the C++ Array
You can use square brackets to access the elements of the C++ Array. Inside square brackets, use the index number of the element you want to access. Indexing in C++ starts from 0.
cout << city[0];
// Outputs Agra
Looping a C++ Array
#include <iostream>
#include <string>
using namespace std;
int main() {
string city[5] = {"Agra", "Delhi", "Noida", "Gurgaon", "Banglore"};
for(int i = 0; i < 5; i++){
cout << city[i] << "\n";
}
return 0;
}
Output:

Also Read:
- ChatGPT Asked a person to commit suicide to solve the problem
- Viral Moment: China’s AgiBot X2 Makes History With World’s First Webster Backflip
- Terminator Rising: Albania Hands Power to AI, Echoing a Nightmare of Human Extinction
- What Is Albania’s World-First AI-Generated Minister and How Does It Work?
- Does ChatGPT believe in God? ChatGPT’s Personal Opinion
- ChatGPT vs Human: The Breath-Holding Chat That Ends in “System Failure”
- What Is Vibe Coding? The Future of No-Code Programming and Its Impact on Software Developers
- Struggling to Generate Ghibli-Style AI Images? Here’s the Real Working Tool That Others Won’t Tell You About!
- ChatGPT vs DeepSeek: Who is the winner?
- People are becoming AI Engineer with this free course in 2025: Here is how to join this…
- Apply to Google’s Student Training in Engineering Program (STEP) Intern, 2025
- Self-Driving Car Saves Falling Pedestrian, Showcases Promise of Autonomous Technology
- Instant Karma: Employer Fires Tech Team with AI, Faces Backlash on LinkedIn While Seeking New Developers
- LinkedIn’s COO Reveals the AI Interview Question That Could Land You the Job in 2025
- Elon Musk’s xAI Raises $6 Billion, Valued at $45 Billion
- Google Unveils Veo 2 and Imagen 3: A New Era of AI-Generated Content
- Imagination to Reality, Unlocking the Future: Genesis Physics Engine for 4D Simulation
- Simple Code to compare Speed of Python, Java, and C++?
- Falling Stars Animation on Python.Hub October 2024
- Most Underrated Database Trick | Life-Saving SQL Command
- Python List Methods
- Top 5 Free HTML Resume Templates in 2024 | With Source Code
- How to See Connected Wi-Fi Passwords in Windows?
- 2023 Merry Christmas using Python Turtle
- 23 AI Tools You Won’t Believe are Free
- Write for CopyAssignment.com | Unlock Your Potential: Join CopyAssignment.com as a Blog Writer! 🚀
- Python 3.12.1 is Now Available
- Best Deepfake Apps and Websites You Can Try for Fun
- Amazon launched free Prompt Engineering course: Enroll Now
- 10 GitHub Repositories to Master Machine Learning