This reverts commit 5edf7b35a9
.
arikchakma-feat/badges
parent
5edf7b35a9
commit
706c9db70d
1 changed files with 45 additions and 1 deletions
@ -1 +1,45 @@ |
||||
%23%20%20What%20is%20C%2B%2B%3F%0AC%2B%2B%20is%20a%20general-purpose%20programming%20language%20created%20by%20Bjarne%20Stroustrup%20as%20an%20extension%20of%20the%20C%20programming%20language.%20It%20was%20first%20introduced%20in%201985%20and%20provides%20object-oriented%20features%20like%20classes%20and%20inheritance.%20C%2B%2B%20is%20widely%20used%20in%20various%20applications%20like%20game%20development%2C%20system%20programming%2C%20embedded%20systems%2C%20and%20high-performance%20computing.%0A%0AC%2B%2B%20is%20a%20statically-typed%20language%2C%20meaning%20that%20the%20type%20of%20a%20variable%20is%20determined%20during%20compilation%2C%20and%20has%20an%20extensive%20library%20called%20the%20C%2B%2B%20Standard%20Library%2C%20which%20provides%20a%20rich%20set%20of%20functions%2C%20algorithms%2C%20and%20data%20structures%20for%20various%20tasks.%0A%0AC%2B%2B%20builds%20upon%20the%20features%20of%20C%2C%20and%20thus%2C%20most%20C%20programs%20can%20be%20compiled%20and%20run%20with%20a%20C%2B%2B%20compiler.%20%0A%0A%23%23%20Code%20Example%0A%0AHere's%20a%20simple%20example%20of%20a%20C%2B%2B%20program%20that%20demonstrates%20some%20essential%20features%20of%20the%20language%3A%0A%0A%60%60%60cpp%0A%23include%20%3Ciostream%3E%0A%0A%2F%2F%20A%20simple%20function%20to%20add%20two%20numbers%0Aint%20add(int%20a%2C%20int%20b)%20%7B%0A%20%20%20%20return%20a%20%2B%20b%3B%0A%7D%0A%0Aclass%20Calculator%20%7B%0Apublic%3A%0A%20%20%20%20%2F%2F%20A%20member%20function%20to%20multiply%20two%20numbers%0A%20%20%20%20int%20multiply(int%20a%2C%20int%20b)%20%7B%0A%20%20%20%20%20%20%20%20return%20a%20*%20b%3B%0A%20%20%20%20%7D%0A%7D%3B%0A%0Aint%20main()%20%7B%0A%20%20%20%20int%20x%20%3D%205%3B%0A%20%20%20%20int%20y%20%3D%203%3B%0A%0A%20%20%20%20%2F%2F%20Using%20the%20standalone%20function%20'add'%0A%20%20%20%20int%20sum%20%3D%20add(x%2C%20y)%3B%0A%20%20%20%20std%3A%3Acout%20%3C%3C%20%22Sum%3A%20%22%20%3C%3C%20sum%20%3C%3C%20std%3A%3Aendl%3B%0A%0A%20%20%20%20%2F%2F%20Using%20a%20class%20and%20member%20function%0A%20%20%20%20Calculator%20calc%3B%0A%20%20%20%20int%20product%20%3D%20calc.multiply(x%2C%20y)%3B%0A%20%20%20%20std%3A%3Acout%20%3C%3C%20%22Product%3A%20%22%20%3C%3C%20product%20%3C%3C%20std%3A%3Aendl%3B%0A%0A%20%20%20%20return%200%3B%0A%7D%0A%60%60%60%0A%0AIn%20the%20above%20program%2C%20we%20define%20a%20simple%20function%20%60add%60%20and%20a%20class%20%60Calculator%60%20with%20a%20member%20function%20%60multiply%60.%20The%20%60main%60%20function%20demonstrates%20how%20to%20use%20these%20to%20perform%20basic%20arithmetic.%0A%0A-%20%5BC%2B%2B%20Tutorial%20for%20Beginners%20-%20Full%20Course%5D(https%3A%2F%2Fyoutu.be%2FvLnPwxZdW4Y) |
||||
# What is C++? |
||||
C++ is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language. It was first introduced in 1985 and provides object-oriented features like classes and inheritance. C++ is widely used in various applications like game development, system programming, embedded systems, and high-performance computing. |
||||
|
||||
C++ is a statically-typed language, meaning that the type of a variable is determined during compilation, and has an extensive library called the C++ Standard Library, which provides a rich set of functions, algorithms, and data structures for various tasks. |
||||
|
||||
C++ builds upon the features of C, and thus, most C programs can be compiled and run with a C++ compiler. |
||||
|
||||
## Code Example |
||||
|
||||
Here's a simple example of a C++ program that demonstrates some essential features of the language: |
||||
|
||||
```cpp |
||||
#include <iostream> |
||||
|
||||
// A simple function to add two numbers |
||||
int add(int a, int b) { |
||||
return a + b; |
||||
} |
||||
|
||||
class Calculator { |
||||
public: |
||||
// A member function to multiply two numbers |
||||
int multiply(int a, int b) { |
||||
return a * b; |
||||
} |
||||
}; |
||||
|
||||
int main() { |
||||
int x = 5; |
||||
int y = 3; |
||||
|
||||
// Using the standalone function 'add' |
||||
int sum = add(x, y); |
||||
std::cout << "Sum: " << sum << std::endl; |
||||
|
||||
// Using a class and member function |
||||
Calculator calc; |
||||
int product = calc.multiply(x, y); |
||||
std::cout << "Product: " << product << std::endl; |
||||
|
||||
return 0; |
||||
} |
||||
``` |
||||
|
||||
In the above program, we define a simple function `add` and a class `Calculator` with a member function `multiply`. The `main` function demonstrates how to use these to perform basic arithmetic. |
Loading…
Reference in new issue