Arrays in C Programming
Declaring an Array
An array in C is a collection of elements of the same data type. To declare
an array we specify the type of elements followed by the name of the array
and then square brackets [] which enclose the number of elements. For
example:
int arr[5];
Indexing an Array
Arrays are 0-indexed, which means that the first element is at index 0. To
access an element in an array, we use the name of the array followed by
the index of the element inside square brackets []. For example, to access
the first element in the above array, we would use:
arr[0];
Manipulating an Array
To manipulate the elements of an array, we can use various operators such
as the assignment operator =, the addition operator +, the subtraction
operator -, the multiplication operator *, and the division operator /.
Example:
arr[0] = 5; // assigns the value 5 to the first element
arr[1] = arr[0] + 2; // assigns the value 7 to the second element
arr[2] = arr[1] * 3; // assigns the value 21 to the third element
Console I/O
In C programming, console input and output is done using the scanf and
printf functions, respectively.
Example:
int num;
Declaring an Array
An array in C is a collection of elements of the same data type. To declare
an array we specify the type of elements followed by the name of the array
and then square brackets [] which enclose the number of elements. For
example:
int arr[5];
Indexing an Array
Arrays are 0-indexed, which means that the first element is at index 0. To
access an element in an array, we use the name of the array followed by
the index of the element inside square brackets []. For example, to access
the first element in the above array, we would use:
arr[0];
Manipulating an Array
To manipulate the elements of an array, we can use various operators such
as the assignment operator =, the addition operator +, the subtraction
operator -, the multiplication operator *, and the division operator /.
Example:
arr[0] = 5; // assigns the value 5 to the first element
arr[1] = arr[0] + 2; // assigns the value 7 to the second element
arr[2] = arr[1] * 3; // assigns the value 21 to the third element
Console I/O
In C programming, console input and output is done using the scanf and
printf functions, respectively.
Example:
int num;