about summary refs log tree commit diff stats
path: root/dev/c/datatypes.html
blob: e406d2c29cc3d8c4c1ac3a17d20309af23d7e8c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>Datatypes</title>
    </head>
    <body>
        <a href="index.html">C index</a>

        <h1>Datatypes</h1>

        <h2 id="types">Types</h2>

        <dl>
            <dt>char</dt>
            <dd>Integer is 1 byte.</dd>

            <dt>int</dt>
            <dd>Integer numbers 4 bytes (short is 2 bytes and long is 4 bytes)</dd>

            <dt>float</dt>
            <dd>Single precision floating point is 4 bytes.</dd>

            <dt>double</dt>
            <dd>Double precision floating point is 8 bytes.</dd>

            <dt>void</dt>
            <dd>Absence of type.</dd>
        </dl>

        <h2 id="datatypes">Data types</h2>

        <h2 id="int">Integer</h2>

        <p>Allowed <a href="elements.html#types">types</a> are char and int;</p>

        <dl>
            <dt>signed char</dt>
            <dd>8 bit, from -128 to 127.</dd>
            <dt>unsigned char</dt>
            <dd>8 bit, from 0 to 255.</dd>
            <dt>char</dt>
            <dd>8 bit, used to store ASCII, ex; 'h', '\n', etc...</dd>
            <dt>short int</dt>
            <dd>16 bit, from -32,768 to 32,767.</dd>
            <dt>unsigned short int</dt>
            <dd>16 bit, from 0 to 65,535.</dd>
            <dt>int</dt>
            <dd>32 bit, from -2,147,483,648 to 2,147,483,647.</dd>
            <dt>unsigned int</dt>
            <dd>32 bit, from 0 to 4,294,967,295.</dd>
            <dt>long int</dt>
            <dd>32 bit, from -2,147,483,648 to 2,147,483,647.</dd>
            <dt>unsigned long int</dt>
            <dd>32 bit, from 0 to 4,294,967,295.</dd>
            <dt>long long int</dt>
            <dd>64 bit, from 9,223,372,036,854,775,808
            to 9,223,372,036,854,775,807.</dd>
            <dt>unsigned long long int</dt>
            <dd>64 bit, from 0 to 18,446,744,073,709,551,615.</dd>
        </dl>

        <h2 id="double">Real number</h2>

        <p>Real numbers are fractional numbers, all floating points
        are signed. Check float.h.</p>

        <dl>
            <dt>float</dt>
            <dd>From 1e-37 to 1e37</dd>
            <dt>double</dt>
            <dd>Largest of floating point.</dd>
            <dt>long double</dt>
            <dd>The long double data maybe larger than double</dd>
        </dl>

        <h2 id="complex">Complex number</h2>

        <p><a href="https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Standard-Complex-Number-Types">Complex Number Types</a></p>

        <h2 id="enum">Enumeration</h2>

        <pre>
        enum colors {black, orange, blue} color;
        enum colors color;
        </pre>

        <h2 id="union">Unions</h2>

        <pre>
        union accounts {
            int id;
            float value;
        } first_account, second_account;
        </pre>

        <h2 id="struct">Structures</h2>

        <pre>
        struct point {
            int x, y, z;
        } first_point;
        struct point second_point;
        </pre>

        <h2 id="array">Arrays</h2>

        <pre>
        int account_array[9];
        int account_array[] = {0, 1, 2, 3};
        int account_array[] = {0, 1, 2, [9] = 9};
        </pre>

        <pre>
        int account_array[2][9] { {1,2,3},{9,8,7} }
        </pre>

        <p>Initializing string with individual characters the
        null character must be defined;</p>

        <pre>
        char black[] = {'b', 'l', 'a', 'c', 'k', '\0'}
        </pre>

        <pre>
        char black[] = "black";
        </pre>

        <pre>
        union accounts {
            int id;
            float value;
        };
        union accounts accounts_array[9];
        accounts_array[0].id = 8;
        </pre>

        <pre>
        struct point {
            int x, y;
        };
        struct point point_array[9];
        point_array[0].x=2;
        point_array[0].y=3;
        </pre>

        <h2 id="pointer">Pointers</h2>
        <h2 id="it">Incomplete types</h2>
        <h2 id="tq">Type qualifiers</h2>
        <h2 id="st">Storage class</h2>

        <h2 id="format">Format Type Specifiers</h2>

        <dl>
            <dt>%c</dt>
            <dd>Character</dd>
            <dt>%s</dt>
            <dd>String of characters</dd>
            <dt>%d</dt>
            <dd>Decimal integer</dd>
            <dt>%f</dt>
            <dd>Decimal floating point</dd>
            <dt>%llu</dt>
            <dd>unsigned long long</dd>
            <dt>%o</dt>
            <dd>Signed octal</dd>
            <dt>%u</dt>
            <dd>Unsigned decimal integer</dd>
            <dt>%x</dt>
            <dd>Unsigned hexadecimal integer</dd>
            <dt>%p</dt>
            <dd>Pointer address</dd>
        </dl>

        <a href="index.html">C Index</a>
        <p>This is part of the LeetIO System Documentation.
        Copyright (C) 2021
        LeetIO Team.
        See the file <a href="../../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>

    </body>
</html>