From the course: C Essential Training
Understanding C language data types - C Tutorial
From the course: C Essential Training
Understanding C language data types
- Programming is about input and output. The old IO, you sing about at computer camp. Input is received, modified, and then output. The stuff that's input, modified and output is data. In the C language data is classified into four types. The data type describes what kind of information is used in your code. The four basic C data types are shown here. Char, to store a single character or byte of information, Int, to store integer or whole number values, and float and double to store real numbers, Which are fractions, are very large or very small values. A float is a single precision value, accurate to 8 digits. And a double is a double precision value accurate to 16 digits. These data types also have qualifiers which can refine the data's scope. For example, the signed qualifier is the default, meaning that an integer value stores both positive and negative numbers, an unsigned qualifier means the integer stores only positive values. In this exercise file, Four data types are listed. Lines 5 through 8 they are characters C, integer I, float F and double D. The scanf functions in the main body of the code, read the input of the different types. The first argument in the function is the data type. The second is the address of the specific variable. Lines 21 to 24 output the results. Nothing is processed here. The information just goes in and it comes back out. Build and run and all types of values. A, for the character. 42, for an integer. Small value one quarter, and the large value, let's do 2.56e12. And you see the results output here. The void data type is also available, void for no data. This type comes into play for allocating memory and referencing functions that return no value or accept no arguments. Unlike other programming languages, C has no string data type. Instead, an array of characters represents a string. This code declares an empty character array at line 5. The data type is char, characters. The name is buffer and it stores room for up to 32 characters. The F gets function at line 8, reads from standard input stdin up to 32 characters, storing them in the buffer. Then line 9 outputs the buffer. Build and run and all type my name. And you see, my name was stored and output. Obviously, a lot goes on with C data types, input, output variables, and all that. But at the core, the C language has these four data types, which describe information used in your code.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Understanding C language data types3m 4s
-
(Locked)
Declaring variables2m 49s
-
(Locked)
Working with variables2m 55s
-
(Locked)
Exploring the printf() function3m 4s
-
(Locked)
Using constants2m 53s
-
(Locked)
Challenge: Make variables and constants47s
-
Solution: Make variables and constants1m
-
(Locked)
Understanding variable scope3m 8s
-
(Locked)
Making new data types3m 24s
-
(Locked)
Specifying characters and strings3m 17s
-
(Locked)
Specifying integers and real numbers4m 14s
-
(Locked)
Typecasting a variable3m 11s
-
(Locked)
Challenge: Basic I/O1m 10s
-
(Locked)
Solution: Basic I/O1m 35s
-
-
-
-
-