Our C++ (basic) (in English)

发布时间:2024年01月14日

What's C++?

C++ is a high-level language . It was designed and developed by Bjarne Stroustrup in 1979 at Bell Labs. C++ is an object-oriented programming language that expands and improves the C language. C++ runs on a variety of platforms, such as Windows, MAC operating systems, and UNIX versions.

C++ is a statically typed, compiled, general-purpose, case-sensitive, irregular programming language that supports procedural, object-oriented, and generic programming.

C++ is considered an intermediate-level language that combines the characteristics of a high-level language with a low-level language.

C++ was designed and developed by Bjarne Stroustrup in 1979 at Bell Labs, Mount Merry, New Jersey. C++ further expanded and refined the C language, initially named C with classes, and later renamed C++ in 1983.

C++ is a superset of C, and in fact, any legitimate C program is a legitimate C++ program.

Note: Programming languages that use static types perform type checking at compile time, not at runtime.

C++ syntax

A C++ program can be defined as a collection of objects that interact with each other by calling each other's methods. Now let's take a brief look at what a class, an object, a method, an instant variable is.

Object

An object has a state and a behavior. For example: the state of a dog - color, name, breed,

behavior

shake, bark, eat. An object is an instance of a class.

Classes

Classes can be defined as templates/blueprints that describe the behavior/state of an object.

Method

Basically, a method represents a behavior. A class can contain multiple methods. You can write logic, manipulate data, and perform all actions in a method.

Instant Variables

Each object has its own unique instant variables. The state of an object is created by the values of these instant variables.

An easy C++ code

#include <iostream>
using namespace std;
 
// using namespace std is the beginning of the code
 
int main()
{
   cout << "Hello World"; // output Hello World
   return 0;
}

Type of data

Boolean? ? ? ?bool
Character? ? char
integer? ? ? ? ? ?int
floating-point float
Double floating-point double
Untyped void

The type of data
Booleanbool
Characterchar
Integerint
Floating-pointfloat
Double floating-pointdouble
Untypedvoid
Note:long long's limit is bigger than long's limit than int's limit.

Input & output in C++

Input

//When you want to input something, you should use one of them. (sort by time spent) (from big to small)
For example, if you want to input an integer x, you can use them.  
cin >> x;
scanf("%d",&x);
/*
When you input in "scanf", you should be careful, because the different type of data have different way to input.
For example, if you want to input x, if the data type of x is one of them, you should:
    type                      way to input
1.long long                 scanf("%lld",&x);
2.long                      scanf("%ld",&x);
3.int                       scanf("%d",&x);
4.char                      scanf("%c",&x);
5.double                    scanf("%lf",&x);
6.float                     scanf("%f",&x);
7.string                    scanf("%s",&x);
8.Octadecimal integer       scanf("%o",&x);
9.Hexadecimal integer       scanf("%c",&x);
10.None                     scanf("%*",&x);

output

//If you want to output an integer x, you should use one of them.
cout<<x;
printf("%d",&x);
//Precautions of output is similar to precautions of input.

文章来源:https://blog.csdn.net/A3024857/article/details/135580704
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。