Arrays

An array variable is a collection of elements laid out consecutively in memory. All elements have the same declared type. Individual elements are accessed with the [] notation must come after the variable name.
The actual value of an array variable is a memory address in C.

This is the declaration of an array that can hold 12 integer values:

int c[12]

The first element can be accessed with c[0] and the last element is always one less than the size of the array (i.e., c[11]).
Assign a value to an element with c[0]=7.

If you try to access your array before initializing, then do not know what value the elements will have and you will get warnings.

Initializing Arrays

With a for loop:

int c[12]; // elements undefined
for (int i = 0; i < 12; i++) {
	c[i] = i; // initialize with value matching index number
}

With literal values by using values separated by commas within { ... }. Array size can be omitted when initializing with { ... }.

int c[5] = {2, 4, 6, 8, 10};

c[ ] = {2, 4, 6, 8} // no size

Whole Array Operations (NOT)

Strings

Strings are a sequence of characters handled as a unit; not a separate type. It is an array of characters with the final character equal to the "null character", \0, also called the "null terminator," and has the first character on the ASCII table with a value of 0.

Two declarations of string. The first declaration shows a string is like an array. The second uses an array with the final character equal to the "null character” and both first and second strings are null-terminated and are arrays of size 7. The third declaration shows a string is like a pointer.

char day[] = "monday";

// same as
char day[] = {'m', 'o', 'n', 'd', 'a', 'y', '\0'}

//alteratively
const char *day_ptr "monday";

String Character Access

Indexing, or accessing elements of the string utilizes square bracket notation.

cnst char str[] = "hello";
print("%c %c \n", str[1], str[2]) // prints "e l"

Printing Strings

Strings are an array of null-terminated (\n) characters. Null termination is used to indicate where the string ends, so it will only print chars up to the (first) \n.

printf("%s", s);

String Functions

Size-related functions that return an unsigned long (%lu format string).

#include<string.h> includes helpful string functions:

String Operations (NOT)