Arrays
An array is a fixed-size homogeneous collection of items stored at a contiguous memory location. It can contain elements from type int, char, float, structure, etc. to even other arrays.
- Array provides random access using the element index.
- Array size cannot change.
- Array can have multiple dimensions in which it can grow.
Syntax of Arrays
data_type arr_name [size1]; // 1D array data_type arr_name [size1][size2]; // 2D array data_type arr_name [size1][size2][size3]; // 3D array
Example of Arrays
C
// C Program to demonstrate the use of array #include <stdio.h> int main() { // array declaration and initialization int arr[5] = { 10, 20, 30, 40, 50 }; // modifying element at index 2 arr[2] = 100; // traversing array using for loop printf ( "Elements in Array: " ); for ( int i = 0; i < 5; i++) { printf ( "%d " , arr[i]); } return 0; } |
Output
Elements in Array: 10 20 100 40 50
C Cheat Sheet
This C Cheat Sheet provides an overview of both basic and advanced concepts of the C language. Whether you’re a beginner or an experienced programmer, this cheat sheet will help you revise and quickly go through the core principles of the C language.
In this Cheat Sheet, we will delve into the basics of the C language, exploring its fundamental concepts that lay the groundwork for programming. We will cover topics such as variables, data types, and operators, providing you with a solid understanding of the building blocks of C programming.
Contact Us