Arrays are static, therefore the length of a string cannot be modified.
Characters in a string can be accessed and modified using indices, the same technique used with arrays.
Strings can be created by initializing an array of char
s.
All strings terminate with a null character ('\0'
).
You can find the length of a string using the strlen()
function.
Two strings can be concatenated using the strcat()
function.
A string can be copied into an empty char
array (empty string) using the strcpy()
function.
An array is used to store many elements of the same type in contiguous blocks of memory
An uninitialized array is created as follows:
type arr[array_size];
An initialized array is created as follows:
type arr[] = {element1, element2, element3, …};
You can access the array element at index idx
as follows:
arr[idx];
The first and last elements in the array can be found at the following indices:
firstElement = arr[0];lastElement = arr[arraySize - 1];
Array size can be found using the sizeof()
function
Arrays can be iterated through using while
loops or for
loops.
Attempting to access or modify an element at an index greater than the length of the array will cause the program to behave unpredictably.
Initialized and uninitialized multidimensional arrays are created as follows:
initializedMultArray = type arr[][dim2Size]…[dimNSize] = {{element1, element2,…},{element1, element2, …}, …};uninitializedMultArray = type arr[dim1Size][dim2Size]…[dimNSize];