🧵 One-Dimensional Array in C++ | Declaration, Initialization, Reading & Writing
🧵 One-Dimensional Array in C++ | Declaration, Initialization, Reading & Writing
Array is a collection of similar type elements under a single variable.
📌 What is a One-Dimensional Array?
A one-dimensional array in C++ is a collection of elements stored in contiguous memory locations. All elements in the array must be of the same data type and can be accessed using a single index.
✅ Declaration of 1D Array
To declare a 1D array:
Example:
✅ Initialization of Array
You can initialize arrays at the time of declaration:
-
Full Initialization:
-
Partial Initialization (remaining values will be zero):
Automatic Size Deduction:
📝 Reading Array Elements
You can use a loop to read input into an array:
📤 Writing (Displaying) Array Elements
To display elements of the array:
<iostream>
using namespace std;
int main() {
int marks[5]={12,69,60,21,42};for (int i = 0; i < 5; i++){
cout << "Mark " << i << ": " << marks[i] << endl;
} return 0;
}🧠 Final Thoughts
Arrays are fundamental in C++. Mastering them lays the foundation for working with more complex data structures. One-dimensional arrays are great for storing linear data like marks, temperatures, or names.
Click here to learn more
Download MPC Examinations & Marking Guides 2022–2024 – Free PDF Access
Download MPC Examinations & Marking Guides 2022–2024 – Free PDF Access
📘 L4 BDC (Building Construction Technology) Examinations & Marking Guides
Important notice
⚠️ All Jobs and Opportunities published on fdo.net.rw are completely free to apply.
Never pay any fee during the recruitment process!
Even if fdo.net.rw does its best to avoid scam job or opportunity offers, job seekers or opportunity seekers are 100% responsible for applying at their own risk.
Check carefully before applying. If you doubt the legitimacy of any offer, do not apply and contact us at
freedigopp54@gmail.com
Never pay to get a job or opportunity - if you do, you do so at your own risk.
