Week 4: Memory Maps / String Functions / Simple I/O Flashcards
A char takes how many bytes
1 byte
An int takes how many bytes
4 bytes
A float takes how many bytes?
4 bytes
Do different VARIABLES have to be contiguous?
NO
What is in the memory location when a variable is declared?
Whatever was there before
How many statements does the computer see in the following:
int height = 8;
Two, one for declaration and another for initialization
What is a “scalar” variable?
A variable capable of of holding a single data item
What is an “aggregate” variable?
A variable capable of holding a collection of values
arrays and structures
What are the two kinds of aggregate variables in C?
Arrays and structures
What is an array initializer?
The contents of an array enclosed in curly brackets
{1,2,3,4,0,0,0}
What does this do?
int a[10];
Declares an array of type int with 10 elements
What does this do?
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Declares an array of type int with 10 elements AND what the elements are
What does this do?
int a[10] = {1, 2, 3, 4, 5, 6};
/* initial value of a is {1, 2, 3, 4, 5, 6, 0, 0, 0, 0} */
The remaining values become 0s
What does this do?
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
If an initializer is present, the length of the array may be omitted:
In the case of no length given for an array, but an initializer is, what does the compiler do?
The compiler uses the length of the initializer
to determine how long the array is.
In C, arrays are stored in what?
C stores arrays in row-major order, with row 0 first, then row 1, and so forth.
(sort of …. )
What is the format of a 3-dimensional array and how are the elements accessed?
int b[2][3][4]; /* a 2 by 3 by 4 table */
2 layers
3 rows
4 columns
Can an array be declared with an expression as the size?
int a[n=1];
Yes
What is a string in C?
An array of characters ending with a special NULL character:
\0
How do you declare a string in C?
char d[8] = “Magic”;
What is the String library in C?
include string.h
What does strlen return with regards to a string?
The length of a NULL terminated string
What does
count = strlen(d);
return if d is “Magic”
5, even though there are 6 values (including the NULL character)
What does strcpy do? Format?
It copies a character string into another string
source should be NULL terminated
destination should have enough room
strcpy(str2, str1);
Whatever was in str2 is replaced with whatever is in str1