Topics
- Declaring, Initializing, and Assigning Variables
int
,char
float
anddouble
types<stdint.h>
types- Literals
- Magic numbers:
const
and#define
static
andextern
modifiersenum
type
Class Slides
Resources
- https://en.wikibooks.org/wiki/C_Programming/Variables
- https://en.wikibooks.org/wiki/C_Programming/Advanced_data_types#Enumerations
Study Questions
- What are variables?
- What is a variable’s type and size?
- What does it mean that C is typed?
- Does an assignment statement return a value?
- What characters can you use in your variable names?
- How do you use hex literals in C?
- What is the
char
datatype used for? - Can you use the
char
datatype to store integers? - (T/F) Floating point types can represent any fractional value.
- What is the value of
sizeof(char)
?sizeof(int)
?sizeof(int32_t)
? - (T/F) A
long int
is always larger than anint
? - What does the
const
qualifier do? - What does
#define
do? - Should you end
#define
directives with a semicolon? - What happens if you put
static
in front of:- A function?
- A global variable?
- A local variable?
- What is
extern
used for? Does it allocate memory for variables? -
What is the
enum
type used for? What value does it start at? Can you override it? - What does the following code print?
#include <stdio.h> #define PLUS1 x+1 int main() { int x = 10; int y = 5 * PLUS1; printf("%d\n", y); }
- What is the name of the mystery function shown below (it is a standard library function):
int mystery(char s[]) { int i = 0; while (s[i] != '\0') ++i; return i; }
- What does the code below print out?
#include <stdio.h> int main() { enum {hello=3, goodbye} myEnum = goodbye; printf("%d\n", myEnum); }
-
(T or F) In the program above, myEnum is an automatic (local) variable.
- What does the following program print out?
#include <stdio.h> int main() { printf("%d\n", '1'); }
- What does the following program print out?
#include <stdio.h> int main() { printf("%d\n", "13"); }