From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Declaring variables - C Tutorial
From the course: Complete Guide to C Programming Foundations
Declaring variables
- [Instructor] A variable is a storage container that holds values that can change. The variable must be declared before it's used. It's given a data type and a name. It can be initialized to a given value, though this assignment can come later. Variables are declared in a statement traditionally at the top of the function they're used in as shown here at the main function, lines five through seven. The format is data type followed by the variable name, character variable c, integer variable i, and float variable f. You can declare a variable elsewhere in the code, which works as long as the variable is declared before it's used. At line 17, double variable d is declared. It's used on the following statement at line 18. Using a variable that's not declared generates an error. If I comment out line 17 and then attempt to run the program, you see the error. This is one reason why I prefer to declare variables at the start of a function. The variable name must start with a letter and can…
Contents
-
-
-
-
Understanding C language data types3m 17s
-
(Locked)
Declaring variables2m 53s
-
(Locked)
Working with variables3m 4s
-
(Locked)
Exploring the printf() function3m 48s
-
(Locked)
Using constants2m 58s
-
Challenge: Making variables and constants53s
-
(Locked)
Solution: Making variables and constants1m 16s
-
(Locked)
Understanding variable scope3m 35s
-
(Locked)
Making new data types3m 25s
-
(Locked)
Specifying characters and strings3m 17s
-
(Locked)
Specifying integers and real numbers3m 55s
-
(Locked)
Typecasting a variable2m 20s
-
(Locked)
Chapter challenge: Adding variables and constants1m 10s
-
(Locked)
Chapter solution: Adding variables and constants2m 7s
-
-
-
-
-
-
-
-
-
-