Arrays
Arrays are data structures that are utilized to store and manipulate collections of elements. In languages, like C and C++ arrays are declared with a predetermined size. Initialized with values while in Java, dynamic arrays can be initialized using braces. Python on the hand provides a syntax for creating arrays. Regardless of the programming language used elements, within arrays can be accessed through indices, enabling retrieval and manipulation of data stored in the arrays.
- Create Arrays
- Initialize Arrays
- Access elements in arrays
#include <iostream>
int main()
{
// Creating and Initializing an array
int myArray[5] = { 1, 2, 3, 4, 5 };
// Accessing elements in the array
for (int i = 0; i < 5; i++) {
std::cout << "Element at index " << i << ": "
<< myArray[i] << std::endl;
}
return 0;
}
#include <stdio.h>
int main() {
// Creating and Initializing an array
int myArray[5] = {1, 2, 3, 4, 5};
// Accessing elements in the array
for (int i = 0; i < 5; i++) {
printf("Element at index %d: %d\n", i, myArray[i]);
}
return 0;
}
public class Array {
public static void main(String[] args)
{
// Creating and Initializing an array
int[] myArray = { 1, 2, 3, 4, 5 };
// Accessing elements in the array
for (int i = 0; i < myArray.length; i++) {
System.out.println("Element at index " + i
+ ": " + myArray[i]);
}
}
}
# Creating and Initializing an array
my_array = [1, 2, 3, 4, 5]
# Accessing elements in the array
for i in range(len(my_array)):
print("Element at index {}: {}".format(i, my_array[i]))
// Creating and Initializing an array
let myArray = [1, 2, 3, 4, 5];
// Accessing elements in the array
for (let i = 0; i < 5; i++) {
console.log("Element at index " + i + ": " + myArray[i]);
}
Output
Element at index 0: 1 Element at index 1: 2 Element at index 2: 3 Element at index 3: 4 Element at index 4: 5
How to Start Coding
In this ever-evolving digital landscape, the ability to code is not just a valuable asset but a gateway to creative expression and innovation. This brief guide will outline practical steps and essential principles to guide aspiring learners on their path to mastering the art of coding.
Table of Content
- Introduction, to Basic Syntax. Hello World
- Understanding Data Types
- Variables and Constants
- Keywords
- Operators
- Decision Making statements
- Loops
- Numbers
- Characters
- Arrays
- Strings- Basic String Concepts
- Functions
Contact Us