1D Array
1D Array
One-dimensional Arrays
Data Types
Integral
Floating-Point
(int, bool, Enumeration Arrays structs Classes
(double, …)
char, …)
Arrays
The compiler will catch this error and refuse to run the
program.
Arrays as Parameters to Functions
• When used as function parameters, arrays are
always passed by reference (never by value).
• But you do not use the symbol & when
declaring an array as a formal parameter.
• Example:
Discussed in Chapter 7.
type.
Discussed in Chapter 8, but we won’t use it. 40
A Brief Look at C-Strings
• A character array is an array whose elements
are of type char.
• A C-string is a special type of character array:
it is a null-terminated character array, which
means that it ends with the null character.
– The null character is the character whose ASCII
code is 0. To type it in a program, you type '\0'.
Example:
char name[10] = “John”;