• Variables

    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
  • Data types

    What are data type's?

    • data types specifies what type of information is stored by the variable
    • C has many type's available, they are listed here

    Why use data type's?

    • so the program knows how much memory to allocate and how to interpret the allocated memory
    • C requires all variables to be type'd
      • some programming languages don't require type'ing
      • here's an article on dynamic vs static type'ing, you can just read the conclusion

    How to use data type's?

    • to declare an integer number: int i_am_an_integer;
    • to declare a character: char i_am_a_char;
    • to declare a decimal number: float i_am_a_float;
    • to declare a decimal number with higher precision: double i_am_a_double;
  • Variables Example

    variables.c:

    Things to note:

  • Assignment

    Homework Problem 3.1, at the end of this problem you should submit to Laulima:

    • a file named UHusername_03_1.c

      example:

      • zhaol_03_1.c
    • Write a program that:

      • initializes a variable to 1.2345
      • and outputs the following by using just that variable and 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
      • Note that the exponentials is still displayed from a single variable. It is not a concatenation of numbers and characters
      • To convert the variable to a negative number just multiply it by -1 when you pass it to printf, like this -1*your_variable
      • Do not "hardcode" characters into the output, such as printf("00%f", variable);
      • If you are stuck, you can use the following template: