Jun 22, 2024
int
, float
, char
, double
, etc.int a = 5;
a
of type int
with value 5
.int a = 5
:
5
is converted to binary and stored in these 4 bytes.0x64
).General Syntax:
data_type array_name[size];
int a[60];
stores 60 integers.Invalid Declarations:
int a[];
(Size must be specified).int a[n];
where n
is a variable (unless using macros).Language-Specific Syntax:
Arrays are a collection of elements of the same data type.
Valid Examples:
int a[5] = {6, 2, 4, 3, 0};
(integers)char b[5] = {'a', 'b', 'c', 'd', 'e'};
(characters)float c[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
(floats)Invalid Examples:
int d[5] = {1, 'a', 3, 'b', 5};
(mixed data types)a[0]
for the first element).base_address + (index * size_of(data_type))
Compile-Time Initialization:
int arr[5] = {6, 2, 4, 3, 0};
Run-Time Initialization:
scanf
in C).int arr[5];
for(int i = 0; i < 5; i++) {
scanf("%d", &arr[i]);
}