Variables
Learn about variables in C.
StartKey Concepts
Review core concepts you need to learn to master this subject
C Variable Names
C Variable Names
In C variable names must follow specific rules:
- Names can only be composed of upper and lower case letters, numbers, and underscores.
- The first character must be a letter (upper or lower case).
- No keywords are allowed as the full name (
int
is not allowed butint_count
would work).
Variables: Lesson
Lesson 1 of 1
- 1In 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…
- 2We 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…
- 3What 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…
- 5Let’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…
- 6So 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…
- 7Before, 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…
- 9Sometimes 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…
- 10A 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…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory