Summary - Variables
- C course
- Beginner
- Lesson 12/116
- 5 min
Declare typed variables to write a small profile program.
Summary - Variables
In this group we covered the basics of variables:
- When declaring, write the type first, then the name
=assigns;==tests equalityconstdefines immutable constants- We learned block scope and global scope
typedefgives types new names
Now solidify what you learned with two small tasks.
Practice Write a program with const
Write a C program: define const int LIMIT = 10; and print LIMIT with printf using %d.
Sample solution
#include <stdio.h>
int main(void) {
const int LIMIT = 10;
printf("%d", LIMIT);
return 0;
}Expected output
10
Practice Use typedef
Define typedef int Count;. Declare a Count variable (7 for example) and print it with printf using %d.
Sample solution
#include <stdio.h>
typedef int Count;
int main(void) {
Count c = 7;
printf("%d", c);
return 0;
}Expected output
7
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Match the core concepts
| Term | Meaning |
|---|---|
int |
Integer |
const |
Constant |
typedef |
Alias |
double |
Decimal |
2 Which is the correct const usage?
- const int x = 5; Correct answer
- const 5 x;
- 5 const x;
- const = 5;
Explanation: const int x = 5; has the type and name together.