Posts

Showing posts with the label Arrays

Arrays in Kotlin

  In Kotlin, arrays are used to store multiple values of the same type in a single variable. Kotlin provides several ways to create and work with arrays. Here's an overview of arrays in Kotlin: 1.  Creating Arrays Kotlin provides the  arrayOf()  function to create arrays of a specific type. Example: kotlin Copy val numbers = arrayOf ( 1 , 2 , 3 , 4 , 5 ) // Array of integers val names = arrayOf ( "Alice" , "Bob" , "Charlie" ) // Array of strings For primitive types, Kotlin provides specialized array classes like  IntArray ,  DoubleArray ,  BooleanArray , etc., which are more efficient. Example:

Arrays in C++

Arrays in C++ are fundamental data structures that store elements of the same type in contiguous memory. Here's a structured overview:  **1. Declaration and Initialization** - **Static Arrays**: Fixed size determined at compile-time.   ```cpp   int arr[5];             // Uninitialized array of 5 integers   int arr[] = {1, 2, 3};  // Size inferred as 3   int arr[5] = {1, 2};    // Initialized to {1, 2, 0, 0, 0} (remaining elements zeroed)   ``` - **Dynamic Arrays**: Size determined at runtime using `new`/`delete`.   ```cpp   int size = 10;   int* arr = new int[size]; // Allocate memory   delete[] arr;             // Deallocate to avoid leaks   ```  **2. Access and Iteration** - Zero-indexed, accessed via `[]`. - Use loops to iterate:   ```cpp   for (int i = 0; i < 5; ++i)        cout << arr[i] << " ";...

Arrays in C#

  Arrays in C# In C#, arrays are a collection of variables that share the same data type. They provide a convenient way to store and manipulate multiple values under a single name. Types of Arrays in C# Single-Dimensional Arrays: A linear collection of elements, accessed using a single index. Declaration: C# int [] numbers = new int [ 5 ]; // Declares an array of 5 integers Initialization: C# int [] numbers = { 1 , 2 , 3 , 4 , 5 }; // Initializes with values Access: C# int firstNumber = numbers[ 0 ]; // Access the first element Multi-Dimensional Arrays: Arrays with multiple dimensions, accessed using multiple indices.