Topics
- Declaring, Initializing, and Assigning Variables
int,charfloatanddoubletypes<stdint.h>types- Literals
- Magic numbers:
constand#define staticandexternmodifiersenumtype
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
chardatatype used for? - Can you use the
chardatatype 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 intis always larger than anint? - What does the
constqualifier do? - What does
#definedo? - Should you end
#definedirectives with a semicolon? - What happens if you put
staticin front of:- A function?
- A global variable?
- A local variable?
- What is
externused for? Does it allocate memory for variables? -
What is the
enumtype 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"); }