From the course: Learning C++
Variables
- [Instructor] There are a handful of important aspects about variables in C++. Variables are temporary data storage units. They must be declared prior to being used. The declaration of a variable must specify a type and a name, and declarations may contain initializations. In your code, you'll have to assign values to your variables. So let me briefly show you the syntax for some of the most popular types. Integers are entered as numbers with a special format for the radix. The default is decimal, like 123 or minus 5. Now a leading zero means octal like 023. So be careful with this. For hexadecimal, start with 0x, like 0x3A, and for binary, start with 0b as in 0b1100. You may specify unsigned with a trailing upper or lowercase U as in 23U. Floats are entered with the decimal point and at least one digit to the right, even if the value happens to be an integer. And you must specify the float type with a trailing f as in 23.0f or 0.0f. Doubles are the default floating point type. So you write the number like a float literal without the trailing f. Charts may be entered as integers as long as they fit in 8 bits, but their ASCII character interpretation is entered between single quotes. Here we have lowercase a, uppercase X, and two special characters that use the backslash escape character. These are the null character to the limit the end of a string, and the new line character. Finally, you've already seen string literals between double quotes.
Contents
-
-
-
-
(Locked)
Basic data types3m 44s
-
Variables2m 6s
-
(Locked)
Using variables5m 18s
-
Expressions, assignments, and operations3m 52s
-
(Locked)
Type inference with auto3m 5s
-
(Locked)
Preprocessor directives7m 10s
-
(Locked)
Constants1m 58s
-
Arrays6m 44s
-
(Locked)
Strings5m 42s
-
(Locked)
Type casting4m 34s
-
(Locked)
Type casting examples5m 13s
-
(Locked)
Enumerations7m 55s
-
(Locked)
Challenge: Calculate an average57s
-
(Locked)
Solution: Calculate an average54s
-
(Locked)
-
-
-
-
-