What are variables?
- holds information that can be changed
Why use variables?
- programs with information that's predetermined is not very useful
How to use variables?
- declare variables
- initialize variables
- set, change, or display variables
What are variables?
Why use variables?
How to use variables?
What are data type's?
Why use data type's?
How to use data type's?
int i_am_an_integer;
char i_am_a_char;
float i_am_a_float;
double i_am_a_double;
Things to note:
printf
needs the conversion specifier to know what type the variable isprintf
is not very smart and will do exactly as you tell it, so if you are not careful errors can propagate throughout your programchar
's has a int
representation, http://www.asciitable.comexample:
Write a program that:
printf
zero padding in back of a number: 1.23450 1.234500 1.2345000 zero padding in front of a number: 1.2345 01.2345 001.2345 exponentials (base 10): 1.2345e+00 1.23450e+00 1.234500e+00 truncation vs rounding of numbers: 1.234 negative numbers: -1.2345 -1.2345e+00
printf
, like this -1*your_variable
printf("00%f", variable);