Open links in new tab
  1. A one-dimensional array is a fundamental data structure in computer science that stores a collection of elements of the same data type in a linear sequence. Each element in the array can be accessed individually using its index, which starts from 0. This type of array is known for its simplicity and ease of use in programming.

    Declaration and Initialization

    To declare a one-dimensional array, you need to specify the data type, the array name, and the array size. Here is the syntax for declaring and initializing a one-dimensional array in C:

    // Declaration
    int arr[10]; // Declaring a 1D array of size 10

    // Initialization
    int roll_no[5] = {1, 2, 3, 4, 5}; // Initializing a 1D array of size 5
    char names[30] = {"Raj, John, Krish"}; // Initializing a 1D array of type char

    Accessing and Manipulating Elements

    You can access elements of a one-dimensional array using their index. For example, to access the third element of an array, you use arr[2]. You can also update the elements by assigning new values to specific indices.

    Feedback
Refresh