-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1.html
More file actions
343 lines (241 loc) · 13.4 KB
/
1.html
File metadata and controls
343 lines (241 loc) · 13.4 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C++ Programming</title>
<!-- Favicon -->
<link rel="icon" type="img/png" href="../favicon.png">
<!-- FONT AWESOME -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.1/css/all.css" integrity="sha384-xxzQGERXS00kBmZW/6qxqJPyxW3UR0BPsL4c8ILaIWXva5kFi7TxkIIaMiKtqV1Q" crossorigin="anonymous">
<!-- FONTS -->
<link href="https://fonts.googleapis.com/css2?family=Kalam:wght@700&family=Ubuntu&family=Varela+Round&display=swap" rel="stylesheet">
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- CSS -->
<link rel="stylesheet" href="../cpp_styles.css">
</head>
<body>
<!-- NAVIGATION BAR -->
<nav class="navbar fixed-top navbar-expand-xl navbar-dark">
<a class="navbar-brand" href="../index.html">CODEMISTIC</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="../index.html">Home</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link" href="#features">Features</a>
</li> -->
<li class="nav-item">
<a class="nav-link" href="../tutorials.html">Tutorials<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../campus.html">Campus Programme</a>
</li>
<!-- <li class="nav-item">
<a class="nav-link" href="https://docs.google.com/forms/d/e/1FAIpQLSc2O28YJpxQc6kh2tKpI_Lf5MwfwGXVnhMs0g5EEXobJ4Beeg/viewform?usp=sf_link" target="_blank">Contribute</a>
</li> -->
<li class="nav-item">
<a class="nav-link" href="../team.html">Our Team</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../register.html">Join Our Community</a>
</li>
</ul>
</div>
</nav>
<!-- HEADING -->
<br>
<section class="para">
<div class=" but ">
<button class="btn btn-md btn-primary "><a href="../cpp.html"><i class="fas fa-arrow-left "></i> Back to Index</a></button>
<br>
<center>
<h2>C++ Variables and Literals</h2><br>
</center>
<h2>C++ Variables</h2>
<p>In programming, a variable is a container (storage area) to hold data.</p>
<p>To indicate the storage area, each variable should be given a unique name (identifier). For example,</p>
<pre>
<code>int age = 14;
</code></pre>
<p>Here, <var>age</var> is a variable of the <code>int</code> data type, and we have assigned an integer value 14 to it.</p>
<p><strong>Note:</strong> The <code>int</code> data type suggests that the variable can only hold integers. Similarly, we can use the <code>double</code> data type if we have to store decimals and exponentials.</p>
<p>We will learn about all the data types in detail in the next tutorial.</p>
<p>The value of a variable can be changed, hence the name <strong>variable</strong>.</p>
<pre>
<code>int age = 14; // age is 14
age = 17; // age is 17
</code></pre>
<hr />
<h3>Rules for naming a variable</h3>
<ul>
<li>A variable name can only have alphabets, numbers and the underscore <code>_</code>.</li>
<li>A variable name cannot begin with a number.</li>
<li>Variable names cannot begin with an uppercase character.</li>
<li>A variable name cannot be a keyword. For example, <code>int</code> is a keyword that is used to denote integers.</li>
<li>A variable name can start with an underscore. However, it's not considered a good practice.</li>
</ul>
<p><strong>Note:</strong> We should try to give meaningful names to variables. For example, <var>first_name</var> is a better variable name than <var>fn</var>.</p>
<hr />
<h2>C++ Literals</h2>
<p>Literals are data used for representing fixed values. They can be used directly in the code. For example: <code>1</code>, <code>2.5</code>, <code>'c'</code> etc.</p>
<p>Here, <code>1</code>, <code>2.5</code> and <code>'c'</code> are literals. Why? You cannot assign different values to these terms.</p>
<p>Here's a list of different literals in C++ programming.</p>
<hr />
<h3>1. Integers</h3>
<p>An integer is a numeric literal(associated with numbers) without any fractional or exponential part. There are three types of integer literals in C programming:</p>
<ul>
<li>decimal (base 10)</li>
<li>octal (base 8)</li>
<li>hexadecimal (base 16)</li>
</ul>
<p>For example:</p>
<pre>
Decimal: 0, -9, 22 etc
Octal: 021, 077, 033 etc
Hexadecimal: 0x7f, 0x2a, 0x521 etc
</pre>
<p>In C++ programming, octal starts with a <code>0</code>, and hexadecimal starts with a <code>0x</code>.</p>
<hr />
<h3>2. Floating-point Literals</h3>
<p>A floating-point literal is a numeric literal that has either a fractional form or an exponent form. For example:</p>
<p><code>0.0000234</code></p>
<p><code>-0.22E-5</code></p>
<p class="note-tip"><strong>Note:</strong> <code>E-5 = 10<sup>-5</sup></code></p>
<hr />
<h3 id="characters">3. Characters</h3>
<p>A character literal is created by enclosing a single character inside single quotation marks. For example: <code>'a'</code>, <code>'m'</code>, <code>'F'</code>, <code>'2'</code>, <code>'}'</code> etc.</p>
<hr />
<h3 id="escapesequence">4. Escape Sequences</h3>
<p>Sometimes, it is necessary to use characters that cannot be typed or has special meaning in C++ programming. For example, newline (enter), tab, question mark, etc.</p>
<p>In order to use these characters, escape sequences are used.</p>
<table>
<tbody>
<tr>
<th>Escape Sequences</th>
<th>Characters</th>
</tr>
<tr>
<td><code>\b</code></td>
<td>Backspace</td>
</tr>
<tr>
<td><code>\f</code></td>
<td>Form feed</td>
</tr>
<tr>
<td><code>\n</code></td>
<td>Newline</td>
</tr>
<tr>
<td><code>\r</code></td>
<td>Return</td>
</tr>
<tr>
<td><code>\t</code></td>
<td>Horizontal tab</td>
</tr>
<tr>
<td><code>\v</code></td>
<td>Vertical tab</td>
</tr>
<tr>
<td><code>\\</code></td>
<td>Backslash</td>
</tr>
<tr>
<td><code>\'</code></td>
<td>Single quotation mark</td>
</tr>
<tr>
<td><code>\"</code></td>
<td>Double quotation mark</td>
</tr>
<tr>
<td><code>\?</code></td>
<td>Question mark</td>
</tr>
<tr>
<td><code>\0</code></td>
<td>Null Character</td>
</tr>
</tbody>
</table>
<hr />
<h3 id="string">5. String Literals</h3>
<p>A string literal is a sequence of characters enclosed in double-quote marks. For example:</p>
<table>
<tbody>
<tr>
<td><code>"good"</code></td>
<td>string constant</td>
</tr>
<tr>
<td><code>""</code></td>
<td>null string constant</td>
</tr>
<tr>
<td><code>" "</code></td>
<td>string constant of six white space</td>
</tr>
<tr>
<td><code>"x"</code></td>
<td>string constant having a single character</td>
</tr>
<tr>
<td><code>"Earth is round\n"</code></td>
<td>prints string with a newline</td>
</tr>
</tbody>
</table>
<p>We will learn about strings in detail in the C++ string tutorial.</p>
<hr />
<h2 id="constants">C++ Constants</h2>
<p>In C++, we can create variables whose value cannot be changed. For that, we use the <code>const</code> keyword. Here's an example:</p>
<pre>
<code>const int LIGHT_SPEED = 299792458;
LIGHT_SPEED = 2500 // Error! LIGHT_SPEED is a constant.
</code></pre>
<p>Here, we have used the keyword <code>const</code> to declare a constant named <code>LIGHT_SPEED</code>. If we try to change the value of <code>LIGHT_SPEED</code>, we will get an error.</p>
<p>A constant can also be created using the <code>#define</code> preprocessor directive. We will learn about it in detail in the C++ Macros tutorial.</p>
<br>
<button class="btn btn-primary pull-right"><a href="2.html">Next Topic <i class="fas fa-arrow-right "></i></a></button>
<br> </section>
<center><br>
<h5>More Topics Uploading soon...</h5>
<hr>
<h7>Do you want to contribute by preparing content for us :</h7>
<div class=" but ">
<button class="btn btn-md btn-primary "><a href="https://docs.google.com/forms/d/e/1FAIpQLSc2O28YJpxQc6kh2tKpI_Lf5MwfwGXVnhMs0g5EEXobJ4Beeg/viewform?usp=sf_link " target="_blank ">Contribute</a></button>
</div>
</center>
<footer class="container-fluid ">
<h4>Made with <i style="color:red " class="fa fa-heart "></i> By - Team CodeMistic</h4>
<p class="foot">© Copyright : Team CodeMistic</p>
<div class="footer-links ">
<h7>Connect With Us</h7><br><br>
<a href="https://www.facebook.com/codemistic " target="_blank "><i class="icons fa-2x fab fa-facebook "
style="color:#3b5998; "></i></a>
<a href="https://www.instagram.com/codemistic " target="_blank "><i class="icons fa-2x fab fa-instagram "
style="color:#e95950; "></i></a>
<a href="https://www.twitter.com/codemistic " target="_blank "><i class="icons fa-2x fab fa-twitter "
style="color:#8accf5; "></i></a>
<a href="https://www.linkedin.com/company/codemistic " target="_blank "><i class="icons fa-2x fab fa-linkedin "
style="color:#88b3ee; "></i></a>
<a href="https://t.me/codemistic " target="_blank "><i class="icons fa-2x fab fa-telegram "
style="color:#65adda; "></i></a>
<a href="https://www.youtube.com/channel/UCS1Iv_kkgQGDwoXtvrlwlag " target="_blank "><i
class="icons fa-2x fab fa-youtube " style="color:red; "></i></a>
</div>
</footer>
<!-- CSS Scripts -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js " integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj " crossorigin="anonymous "></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js " integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo " crossorigin="anonymous "></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js " integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI " crossorigin="anonymous "></script>
</body>
</html>