Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the commonly used sentences in C++

Shulou Source: shulou.com Published: 2022-06-02 18:59:43 09月30日 Update

Editor to share with you what C++ commonly used sentences, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

1. Declare variables

In C++, all variables need to be declared, such as:

Int wordCnt

We declare a variable wordCnt of type int, which tells the compiler two key pieces of information. One is the memory required by the variable, and the other is the name of the block of memory. For example, in this example, we declare an int variable. It occupies 32 binary bits, or 4 bytes, and this block of memory is called wordCnt.

Note: in some languages (such as basic), variables do not need to be declared and can be used directly. But this can cause some problems, such as difficult to check when there is a spelling mistake.

For variable declarations, C++ Primer recommends that you declare a variable before you use it for the first time, whenever possible.

2. Assignment statement

After the variable is declared, we can assign it the value we want through the assignment statement.

For example:

WordCnt = 10

Continuous assignment is supported in C++, for example:

Int wordCnt;int personCnt;int roomCnt;wordCnt = personCnt = roomCnt = 10

This is a continuous assignment, with 10 first assigned to the rightmost roomCnt, then to personCnt, and finally to wordCnt.

3. Cin, cout statement

Cin and cout are also commonly used sentences in C++.

Cin, as its name implies, means read in. It can read data from the screen (terminal) and flow to the variables we specify.

For example:

Int wordCnt;cin > > wordCnt

Cin is the object that inputs data, and the data flows from cin to wordCnt. That is, the data we input at the terminal is read into the wordCnt.

Like cout, we can read many types of data from the terminal, such as floating point numbers, integers, strings, etc. Cin will automatically convert the read data into the corresponding data type and complete the assignment.

When we use cout to output results, we can use multiple

Tags: Functions variables statements clocking data types commonly used memory files articles terminals content writing parameters can be passed name outside part input as the name implies Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information macOS Shulou Technology OPPO Reno