Variables: Lesson
Lesson 1 of 1
  1. 1
    In this lesson you will learn about: 1. The rules for naming variables in C. 2. The main data types in C: int, float, double, and char. 3. Declaring and initializing data types in C, as well as cha…
  2. 2
    We are going to start with the second part of our variable declaration, type variable_name, the variable_name. C does not allow you to throw anything down and call it a variable name, there are som…
  3. 3
    What about that first part of our template type (from type variable_name)? We saw some examples in the previous exercise when you corrected the bad variable names, but let’s talk about what they ar…
  4. 4
    We are going to take a little detour for a minute to help you understand what is going on in the code in the lessons. You might have noticed printf() at the bottom of some exercises. This allows fo…
  5. 5
    Let’s get back to understanding variables in C. Now that we have our variable, we know its name and what it can hold, what do we do with it? Right now it’s empty and doesn’t serve any real purpose…
  6. 6
    So why are there two different types for decimals in C? The short answer is different types for different situations. A float has less precision than a double, 6 vs 15 possible decimal places resp…
  7. 7
    Before, we said that there are two times when you can set a variable’s value. We just examined how to set it at declaration, but if that’s the only place it could be set, variables would have limit…
  8. 8
    In most cases, variable values can be changed in the program, however, there are cases where you do not want to allow for your variables to change value. This is where constants come into play. T…
  9. 9
    Sometimes it’s useful, or even necessary, to change the value type of a variable and use it for other purposes. For instance, if you had a double with a percent score on a test, say 0.95, you would…
  10. 10
    A more interesting casting option is converting a char to a number type, or the other way around. Just like before, you have to be careful how you set this up. In the back-end, a char doesn’t store…
  11. 11
    In this Lesson on variables in C we learned: 1. The rules for naming variables in C. 2. The main data types in C: int, float, double, and char. 3. Declaration and initialization of data types in C,…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo