-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
280 lines (256 loc) · 12.8 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>C++ Programming - Basics</title>
<!-- Material Icons-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded">
<!-- Fontawesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
crossorigin="anonymous" referrerpolicy="no-referrer">
<!-- Custom CSS -->
<link rel="stylesheet" href="/src/styles/styles.css?cache_refresh">
<link rel="stylesheet" href="/src/styles/code.css?cache_refresh">
<!-- Javascript -->
<script src="/src/scripts/main.js"></script>
</head>
<body>
<!-- Navigation Bar -->
<nav>
<ul>
<li onclick="toggleSidebar()"><a><span class="material-symbols-rounded">menu</span></a></li>
<li><a href="#">C++ - Basics</a></li>
</ul>
</nav>
<aside class="sidebar" id="sidebar">
<div class="closeBtn"><span onclick="toggleSidebar()" class="material-symbols-rounded">close</span></div>
<div class="navigationContainer">
<ul class="dropdown-menu">
<li class="active">
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/index">Basics</a>
</div>
<ul class="dropdown-content">
<li><a href="/index#introduction">Introduction</a></li>
<li><a href="/index#getting-started">Getting Started</a></li>
<li><a href="/index#simple-program">Writing a Simple Program</a></li>
<li><a href="/index#data-types">Data Types</a></li>
<li><a href="/index#variables">Variables</a></li>
<li><a href="/index#constants">Constants</a></li>
</ul>
</li>
<li>
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/pages/operators#introduction">Operators</a>
</div>
<ul class="dropdown-content">
<li><a href="/pages/operators#introduction">Introduction</a></li>
<li><a href="/pages/operators#arithmetic">Arithmetic Operators</a></li>
<li><a href="/pages/operators#relational">Relational Operators</a></li>
<li><a href="/pages/operators#assignment">Assignment Operators</a></li>
<li><a href="/pages/operators#logical">Logical Operators</a></li>
</ul>
</li>
<li>
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/pages/comments#introduction">Comments</a>
</div>
<ul class="dropdown-content">
<li><a href="/pages/comments#introduction">Introduction</a></li>
</ul>
</li>
<li>
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/pages/control-structures#introduction">Control Structures</a>
</div>
<ul class="dropdown-content">
<li><a href="/pages/control-structures#introduction">Introduction</a></li>
</ul>
</li>
<li>
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/pages/loops#introduction">Loops</a>
</div>
<ul class="dropdown-content">
<li><a href="/pages/loops#introduction">Introduction</a></li>
</ul>
</li>
<li>
<div class="navLink">
<button class="dropdown-toggle"></button>
<a href="/pages/functions#introduction">Functions</a>
</div>
<ul class="dropdown-content">
<li><a href="/pages/functions#introduction">Introduction</a></li>
</ul>
</li>
</ul>
</div>
</aside>
<div class="content">
<main id="introduction">
<h2>Introduction:</h2>
<p>C++ was developed by <strong>Bjarne Stroustrup</strong> at Bell Labs during the early 1980s. It was
designed
to
support the features of C such as <strong>efficiency</strong> & low-level support for system coding. New
features
added were classes with inheritance & virtual functions, were inspired from <strong>Simula67</strong>
language, &
<strong>Operator overloading</strong> was inspired from <strong>Algol68</strong>. Described as
<strong>superset of
C</strong>, C++ has full support for <strong>object-oriented programming (OOPs)</strong>.
</p>
</main>
<hr>
<section id="getting-started">
<h2>Getting Started:</h2>
<p>To write any C++ Program, you need a text editor. Text editor allows you to create & modify text files
(<strong>Notepad++</strong>, <strong>Sublime</strong>, etc). After writing the code we must make sure
that it is
error-free, this process is known as <strong>Compilation</strong> & <strong>Compiler</strong> is used to
make sure
that our code is error-free. It converts the code into machine understandable code (object code) & also
displays
syntax errors (if present) in the program.</p>
<p>C++ programs can be created using any text editor. Some systems like <strong>Visual Studio</strong> &
<strong>Code::Blocks</strong> provide an integrated program development environment under different
operating
systems (like Windows, Linux). IDE Provides a built-in text editor & a compiler. C++ programs can be
also compiled
using command-line tools (like <strong>g++</strong> & <strong>clang++</strong>).
</p>
</section>
<hr>
<section id="simple-program">
<h2>Writing a Simple C++ Program:</h2>
<div class="code">
<pre>
<span class="header">#include <iostream>
using namespace std;</span>
<span class="function">int main()</span> {
<span class="keyword">cout</span> << "Hello, World.";
<span class="keyword">return</span> 0;
}
</pre>
</div>
<h3>Program Explanation:</h3>
<p>Here the <code class="highlight header">#include <iostream></code> in the program deals with
including of
header file (iostream is Input-Output Stream, also known as Preprocessor Directive) it is needed to
support all
built-in functions like <code class="highlight keyword">cout</code> (in this example), <code
class="highlight header">using namespace std;</code> allows us to access elements from Standard C++
Library.</p>
<p>The the fourth line is the Main Function within the body of which you start writing the code for your
program. Every
C++ Program must include one & only one main function.</p>
<p>The code written between the curly braces { } is the program body, the 5th line will output the text
enclosed in
quotation marks ("") on the console. The sixth line <code class="highlight keyword">return 0;</code> is
used to
indicate that the program is executed successfully.</p>
<h3>Program Output:</h3>
<div class="code">
<pre>
Hello, World.
</pre>
</div>
</section>
<hr>
<section id="data-types">
<h2>Data Types:</h2>
<p>The chart below shows various data types in C++,</p>
<a href="/src/images/data-types.png"><img src="/src/images/data-types.png" class="dataTypeImg"></a>
<h3>Basic Datatypes:</h3>
<ol type="1">
<li><strong>int:</strong> It stands for 'integer' and is used to represent whole numbers.</li>
<li><strong>char:</strong> It stands for 'character' and is used to represent characters such as
letters.</li>
<li><strong>float:</strong> It is used to represent decimal numbers with upto 6-7 digits.</li>
<li><strong>double:</strong> It is similar to float but can hold more decimal places with upto 15-16
digits.</li>
<li><strong>void:</strong> It is used as the return type for functions that do not return a value.</li>
</ol>
</section>
<hr>
<section id="variables">
<h2>Variables:</h2>
<p>Variables are used to store information/data. The data stored in a variable can be changed during program
execution.
In C++ all variables must be declared before use.</p>
<h3>Rules for Declaring Variables in C++:</h3>
<ol type="i">
<li>Variable names must start with a letter (A to Z) & (a to z).</li>
<li>Data type must be specified before declaring the variable name.</li>
<li>Keywords (like <code class="highlight keyword">int</code>, <code
class="highlight keyword">float</code>, <code class="highlight keyword">return</code>, <code
class="highlight keyword">char</code>) cannot be used as
variables name.</li>
<li>Variables with two same names can't be declared.</li>
<li>Variables cannot contain whitespaces.</li>
<li>Variables cannot contain special characters except underscores.</li>
</ol>
<br>
<h3>Syntax for Declaration of a Variable:</h3>
<div class="code">
<pre>
<span class="keyword">datatype</span> <span class="variable">variable_name</span>;
</pre>
</div>
<h3>Example:</h3>
<div class="code">
<pre>
<span class="header">#include <iostream>
using namespace std;</span>
<span class="function">int main()</span> {
<span class="keyword">int</span> <span class="variable">myVar</span> = 58;
<span class="comment">/*Declares a variable named myVar
and assigns integer value of 58 to it*/</span>
<span class="keyword">return</span> 0;
}
</pre>
</div>
</section>
<hr>
<section id="constants">
<h2>Constants:</h2>
<p>Constants are declared with the <strong>"const"</strong> keyword, a type, their name, and an assignment
of their
constant value. This value must match the declared type, & its fixed (constant) for the duration of the
programs.</p>
<h3>Example:</h3>
<div class="code">
<pre>
<span class="header">#include <iostream>
using namespace std;</span>
<span class="function">int main()</span> {
<span class="keyword">const int</span> <span class="variable">pie</span> = 3.14;
<span class="comment">/*Declares a constant named pie
and assigns integer value of 3.14 to it*/</span>
<span class="keyword">return</span> 0;
}
</pre>
</div>
</section>
<hr>
<section>
<h2>Congratulations!</h2>
<p>Welcome to the programming club! You finished learning the basics of C++!</p>
</section>
<hr>
<footer>
<h3>Next: <a href="/pages/operators.html">Operators in C++</a></h3>
<p>Found any Error or Mistake? <a href="mailto:[email protected]">Let me know by clicking here</a>
</p>
</footer>
</div>
</body>
</html>