You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.
171
+
*C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.
169
172
170
-
It is a very popular language, despite being old.
173
+
*It is a very popular language, despite being old.
171
174
172
-
C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
175
+
*C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
173
176
174
177
**NOTE**
175
178
C and C++ uses the same compiler and IDE
176
179
</p>
177
180
178
-
<h4> Quick Start :</h4>
181
+
###Quick Start :
179
182
180
183
<p>
181
184
@@ -194,14 +197,151 @@ int main() {
194
197
return 0;
195
198
}
196
199
```
200
+
201
+
<aid="differences"></a>
202
+
<hr><br><br>
203
+
204
+
## Differences between <imgsrc="https://img.shields.io/badge/C-00599C?style=flat&logo=c&logoColor=white"> and <imgsrc="https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white">
205
+
206
+
* C++ was developed as an extension of C, and both languages have almost the same syntax.
207
+
208
+
* The main difference between C and C++ is that C++ support classes and objects, while C does not.
209
+
210
+
211
+
<aid="compiler"></a>
212
+
<hr><br><br>
213
+
214
+
## C++/C Compiler on different OS
215
+
216
+
217
+
<p><b>For Windodws, Linux and MacOS</b><br>
218
+
* Install `code::blocks` by going to there oficial website, <ahref="www.codeblocks.org/downloads/">Code Blocks</a>
219
+
</p>
220
+
<p>
221
+
<b>For Andriod OS</b><br>
222
+
* Install `C4Droid` on playstore, <ahref="https://play.google.com/store/apps/details?id=com.n0n3m4.droidc">C4Droid</a>
223
+
</p>
224
+
<p>
225
+
<b>For IOS</b><br>
226
+
* Visit Appstore and download <ahref="https://apps.apple.com/us/app/c-c-program-compiler/id1160868782">C/C++ Program Compiler</a>
1. Let's break up the following code to understand it better:
237
+
238
+
```
239
+
#include <iostream>
240
+
using namespace std;
241
+
242
+
// main() is where program execution begins.
243
+
int main() {
244
+
cout << "Hello World"; // prints Hello World
245
+
return 0;
246
+
}
247
+
```
248
+
249
+
<b>Example Explained:</b>
250
+
251
+
**Line 1:**`#include <iostream>` is a header file library that lets us work with input and output objects, such as cout (used in line 5). Header files add functionality to C++ programs.
252
+
253
+
**Line 2:**`using namespace std` means that we can use names for objects and variables from the standard library.
254
+
255
+
**Line 3:** A blank line. C++ ignores white space. But we use it to make the code more readable.
256
+
257
+
**Line 4:** Another thing that always appear in a C++ program, is `int main()`. This is called a function. Any code inside its curly brackets {} will be executed.
258
+
259
+
**Line 5:**`cout` (pronounced "see-out") is an object used together with the insertion operator (<<) to output/print text. In our example it will output "Hello World".
197
260
198
-
## Differences [](#welcome) between <imgsrc="https://img.shields.io/badge/C-00599C?style=for-the-badge&logo=c&logoColor=white"> and <imgsrc="https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge&logo=c%2B%2B&logoColor=white">
261
+
**Note:** Every C++ statement ends with a semicolon ;.
199
262
200
-
C++ was developed as an extension of C, and both languages have almost the same syntax.
263
+
**Note:** The body of `int main()` could also been written as:
264
+
``` int main () { cout << "Hello World! "; return 0; } ```
201
265
202
-
The main difference between C and C++ is that C++ support classes and objects, while C does not.
266
+
**Remember:** The compiler ignores white spaces. However, multiple lines makes the code more readable.
203
267
268
+
**Line 6:**`return 0` ends the main function.
204
269
270
+
**Line 7:** Do not forget to add the closing curly bracket `}` to actually end the main function.
| \n or endl | To insert a new line or to break lines |
278
+
| \n\n | create a blank line |
279
+
| \t | Creates a horizontal tab |
280
+
|\\| Inserts a backslash character (\)|
281
+
|\"| Inserts a double quote character |
282
+
283
+
284
+
<hr><br><br>
285
+
<aid="comment"></a>
286
+
287
+
## Comment in C++
288
+
289
+
* Comments can be used to explain C++ code, and to make it more readable.
290
+
* It can also be used to prevent execution when testing alternative code.
291
+
* Comments can be singled-lined or multi-lined.
292
+
293
+
1. Single-line comments start with two forward slashes (//).
294
+
295
+
```
296
+
// This is a comment
297
+
cout << "Hello World!";
298
+
```
299
+
300
+
2. Multi-line comments start with /* and ends with */.
301
+
302
+
```
303
+
/* The code below will print the words Hello World!
304
+
to the screen, and it is amazing */
305
+
cout << "Hello World!";
306
+
```
307
+
308
+
<hr><br><br>
309
+
<aid="variables"></a>
310
+
311
+
## Variables in C++
312
+
313
+
1. Variables are containers for storing data values.
314
+
315
+
In C++, there are different types of variables (defined with different keywords), for example:
316
+
317
+
*`int` - stores integers (whole numbers), without decimals, such as 123 or -123
318
+
*`double` - stores floating point numbers, with decimals, such as 19.99 or -19.99
319
+
*`char` - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
320
+
*`string` - stores text, such as "Hello World". String values are surrounded by double quotes
321
+
*`bool` - stores values with two states: true or false
322
+
323
+
2. To create a variable, specify the type and assign it a value:
324
+
`type variableName = value;`
325
+
326
+
**Note:** Where `type` is one of C++ types (such as `int`), and `variableName` is the name of the variable (such as x or myName). The equal sign is used to assign values to the variable.
327
+
328
+
3. Variable Declaration:
329
+
*
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
205
345
206
346
207
347
@@ -210,8 +350,8 @@ The main difference between C and C++ is that C++ support classes and objects, w
210
350
211
351
212
352
353
+
<hr><br><br><br>
213
354
214
-
<br><br><br>
215
355
<palign="center">Join our <ahref="https://github.com/TYP-Coding-Class/community/issues/new?assignees=&labels=github-invitation&template=invitation.yml&title=Please+invite+me+to+the+community">GitHub Organization :octocat:</a> and continue to contribute to our Open Source Software ✨</p>
0 commit comments