C Programming Language Tutorial
Variables and Data Types
Input/Output
Looping and Selection Structures
Array
Functions
Preprocessing Command
Pointer
Structure
File Operations
Important Knowledge
In the C programming language, arrays are a collection of elements of the same data type, stored in contiguous memory locations. Here are some key points to remember about arrays in C:
Declaring an array: To declare an array in C, you need to specify the data type of the elements in the array and the number of elements in the array. For example, int myArray[5]
declares an array of 5 integers.
Initializing an array: You can initialize the elements of an array when you declare it, or you can assign values to individual elements later. For example, int myArray[5] = {1, 2, 3, 4, 5}
initializes the elements of the array to specific values.
Accessing array elements: You can access individual elements of an array using their index. In C, array indices start at 0, so the first element of an array is at index 0, the second element is at index 1, and so on.
Modifying array elements: You can modify the values of individual elements in an array by assigning a new value to the element using its index.
Multi-dimensional arrays: C also supports multi-dimensional arrays, which can be thought of as matrices with rows and columns. To declare a two-dimensional array in C, you use the syntax int myArray[3][4]
for example, which declares a 3x4 array of integers.
Pointer to an array: In C, you can declare a pointer that points to the first element of an array. You can then use pointer arithmetic to access the other elements of the array.
Sorting arrays: You can sort the elements of an array in C using a variety of sorting algorithms, such as bubble sort or quicksort.
Arrays are a powerful tool for storing and manipulating large amounts of data in C. Understanding how to declare, initialize, access, and modify array elements, as well as how to use pointers to arrays and sort arrays, is an essential part of programming in C.