1️⃣

2.1 Different Types of Data

In computer science, there are different names for different types of data. For example, you wouldn’t store a number in the same data type that you would store a word in. There are different data types you should use, depending on what you want to store in those data types.

Primitive

The first category of data we’ll go over in this section is primitive data. Primitive data types are basically ones that have already been defined in C. This means that you can use primitive data types without having to code what operations you can do with the data type. Below are the primitive data types used in C:

Integers

• int: This data type can be used to store integers; its values can range from -2,147,483,648 to 2,147,483,647.
• unsigned int: This data type can be used to store positive integers only; its values can range from 0 to 4,294,967,295.
• short: This data type can also be used to store integers; its values can range from -32,768 to 32,767. Notice how the range of values for a short is less than that for an int → this is because using a short requires less memory than using an int.
• unsigned short: This data type can also be used to store positive integers only; its values can range from 0 to 65,535. Notice how the range of values for an unsigned short is less than that for an unsigned int → this is because using an unsigned short requires less memory than using an unsigned int.

Decimals

• float: This data type can be used to store decimal values; its values can range from 1.2 x 10-38 to 3.4 x 1038.
• double: This data type can also be used to store decimal values; its values can range from 2.3 x 10-308 to 1.7 x 10308. Notice how the range of values for a double is greater than that for a float → this is because using a double requires more memory than using a float.
• long double: This data type can also be used to store decimal values; its values can range from 3.4 x 10-4,932 to 1.1 x 104,932. Notice how the range of values for a long double is greater than that for a float and regular double → this is because using a double requires more memory than using a float or a regular double.

Char

• char: This data type can be used to store characters; its values can range from -128 to 127. These numbers represent ASCII values for characters represented on your keyboard.

Non-Primitive

The second category of data we’ll go over in this section is non-primitive data. Non-primitive data types are ones that have not been defined in C, and are used to store groups of values, the values typically being of a primitive data type. We will explain more about each type of non-primitive data-types in later chapters. Below are some examples of non-primitive data types:

• String: a group of characters
• Array: a group of any type of primitive data (examples: int array, char array, double array)

Next Section

2️⃣
2.2 Creating and Naming Variables

⚖️