Arrays Flashcards
It is a variable with a single value
Scalar variable
a continuously allocated nonempty set of objects with a
particular member object type
Array
All you need to know when defining an array is
where the array starts
what type of data is in the array
how many elements are in the array
It is the members of the array
elements
Array variable declarations include
a data type
a variable name
ends with a semicolon
length
Array declaration syntax
type name [length];
To access a particular element of an array, we write
array name [integer value]
It is locating a particular element of an array
Array subscripting or indexing
Elements of an array of length n are indexed
from 0 to n-1
These elements of array subscripting are
lvalues
array declarations can include an
optional initialization
Scalar variables are initialized with
a single value
Arrays are initialized with
a list of values.
The initialization of arrays with a list is enclosed in
curly braces
The list is enclosed in curly braces is also referred to as
the initializer
If the list / initializer is shorter than the array,
the remaining elements of
the array are given the value of 0.
It is illegal for an initializer to be
completely empty
How can we check the size of the array?
Using the sizeof operator
A compile-time unary operator
sizeof operator
Used to calculate the size of its operand
Returns the size of a variable
Gives the size in the unit of byte
used for any data type such as primitives like int, float, char, and also
non-primitives data type as an array, struct
sizeof operator
sizeof operator returns the ____ allocated to that data typr
memory
sizeof operator returns the ___ of a variable
size
sizeof operator syntax
sizeof(operand)
The operand in the sizeof operator may be a
data type
any operand
How can we compute for the length of the array?
Array length = size of array/ size of 1 array element