From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Chapter solution: Adding variables and constants - C Tutorial
From the course: Complete Guide to C Programming Foundations
Chapter solution: Adding variables and constants
(upbeat music) - [Instructor] The first change I made for my solution is to create the constant. Remember, constants must be assigned a value right away as they're declared. Here, it's 3/4, which I'm writing is 0.75, and you could also write it this way. Either way is good, just remember to specify that decimal portion so that the compiler knows it's a floating point number. Next, declare three variables. The next set of comments are replaced with these variables assignments. You could assign any values, so don't be discouraged if you choose values different than mine. Still, the data types must match, single character, integer, floating point value. Finally, come a series of printf statements to output the values. The strings are partially built, so I'll take advantage of that as I convert these comments into C language statements. For a single character, use the %c placeholder. I've enclosed it in single quotes here, which is optional. For integers, use %d. For floating point values…
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
-
-
-
-
-
-
-
-
-
-