MMGameslogo  MMGames
TwitterSharebutton  FacebookSharebutton   
learn through sufferingC Language
learn through sufferingC Language

Types of Variables

Data types
In the previous section, we explained variable declaration and usage.
I didn't explain much about types when declaring variables.

In the previous section, we explained that variables are declared using the following format.

Declare variables.
Type variable name;

A type name is an example of something to remember about the kind of numerical value.
In the previous section, we used int to store integers.
There are many other varieties of this type.

C allows you to work with various types of numbers.
And for each of those values, you need to store them using separate types of variables.
Sometimes, different kinds of numbers are referred to as data types.

キーワード
【Data types】

The type of numerical data, differing in aspects such as the maximum number of digits and whether it's an integer or a real number.


In C, each type is given a separate name.
And it's often referred to as a "so-and-so" type.
Variables that store real numbers.
There aren't many types of data used in C.
For now, just remembering these two things will be enough.

型名 Numeric types
int 整数
double 実数

The variable I just used was of type int.
Besides that, you can also use a variable of another type called double.
While an int data type stores integers, a double data type stores floating-point numbers.

These two are identical in how they're used, differing only in the type of numbers they store.
The following program demonstrates performing arithmetic operations using the double data type.

Source code
#include <stdio.h>

int main(void)
{
    double left, right;
    left = 10;
    right = 3;
    printf("%f\n", left + right);
    printf("%f\n", left - right);
    printf("%f\n", left * right);
    printf("%f\n", left / right);
    return 0;
}

The results of this program's execution are as follows:

Execution results
13.000000
7.000000
30.000000
3.333333

Comparing it with the previous program, you're sure to find that the usage is exactly the same.


About This Site

Learning C language through suffering (Kushi C) is
This is the definitive introduction to the C language.
It systematically explains the basic functions of the C language.
The quality is equal to or higher than commercially available books.

Part 0: Program Overview
  1. What is a program?
Chapter 3: Displaying on the Screen
  1. String Display
  2. newline character
  3. Practice Problem 3
Chapter 4: Displaying and Calculating Numbers
  1. Display of numbers
  2. Basic calculations
  3. Numeric types
  4. Practice Problem 4
Chapter 6: Input from the Keyboard
  1. input function
  2. The fear of input
  3. Practice Problem 6
Chapter 9: Repeating a Fixed Number of Times
  1. Iterative sentence
  2. How Loops Work
  3. Practice Problem 9
Chapter 10: Repeating Without Knowing the Number of Times
  1. Unspecified loop
  2. Input validation
  3. Practice Problem 10
Chapter 13: Handling Multiple Variables at Once
  1. Handling multiple variables collectively.
  2. Arrays
  3. Practice Problem 13
Chapter 19: Dynamic Arrays
  1. Create arrays freely.
  2. Practice Problem 19