Learning the basics and intricacies of the C++ programming language. A textbook with practical tasks and tests. Do you want to learn to program? Then you are in the right place - here is free programming training. Whether you're experienced or not, these programming lessons will help you get started creating, compiling, and debugging C++ programs in a variety of development environments: Visual Studio, Code::Blocks, Xcode or Eclipse.

Lots of examples and detailed explanations. Perfect for both beginners (dummies) and more advanced ones. Everything is explained from scratch to the very details. These lessons (200+) will give you a good base/foundation in understanding programming not only in C++, but also in other programming languages. And it's absolutely free!

Also considered step by step creation games in C++, the SFML graphics library and more than 50 tasks to test your skills and knowledge in C++. An additional bonus is.

For reposting +20 to karma and my gratitude!

Chapter No. 0. Introduction. Getting started

Chapter No. 1. C++ Basics

Chapter No. 2. Variables and basic data types in C++

Chapter No. 3. Operators in C++

Chapter No. 4. Scope and other types of variables in C++

Chapter No. 5. The order in which code is executed in a program. Loops and branches in C++

The C/C++ Standard Library includes a number of functions for reading and writing to the console (keyboard and monitor). These functions read and write data as a simple stream of characters.

The concept of stream, used in programming, is closely related to the ordinary, everyday understanding of this word. The input stream can be compared to a pipe through which water (information) enters a pool (computer memory), and the output stream can be compared to a pipe through which water leaves the pool. An important feature of this pipe is that data can only move in one direction at a time. Even if the same pipe is used for input and output, this cannot happen at the same time: to switch the flow direction, it must be stopped, some action must be performed, and only then the flow can be directed in the opposite direction. Another feature of the stream is that it almost never runs dry. Sometimes it dries out, but this period cannot be long if the system is functioning normally.

The standard output function printf()

The printf() function is a standard output function. Using this function, you can display on the monitor screen a string of characters, a number, the value of a variable...

The printf() function has a prototype in stdio.h
int printf(char *control string, ...);

If successful, printf() returns the number of characters printed.

The control line contains two types of information: characters that are directly printed to the screen, and format specifiers that specify how the arguments are printed.

The printf() function is a formatted output function. This means that in the function parameters you must specify the format of the data that will be output. The data format is specified by format specifiers. The format specifier begins with a % character followed by a format code.

Format specifiers:

%With symbol
%d integer decimal number
%i integer decimal number
%e decimal number in the form x.xx e+xx
%E decimal number in the form x.xx E+xx
%f
%F decimal floating point number xx.xxxx
%g %f or %e, whichever is shorter
%G %F or %E, whichever is shorter
%o octal number
%s character string
%u unsigned decimal number
%x hexadecimal number
%X hexadecimal number
%% symbol %
%p pointer
%n pointer

In addition, l and h modifiers can be applied to format commands.

%ld print long int
%hu stamp short unsigned
%Lf long double stamp

In the format specifier, after the % symbol the precision (number of digits after the decimal point) can be specified. The precision is set as follows: %.n<код формата>. Where n is the number of digits after the decimal point, and<код формата>- one of the codes given above.

For example, if we have a variable x=10.3563 of float type and we want to display its value accurate to 3 decimal places, then we should write:

printf("Variable x = %.3f",x);

Result:
Variable x = 10.356

You can also specify the minimum width of the field allocated for printing. If the line or number is larger than the specified field width, then the line or number is printed in full.

For example, if you write:

printf("%5d",20);

then the result will be as follows:
20

Please note that the number 20 was not printed from the very beginning of the line. If you want the unused spaces of the field to be filled with zeros, then you need to put a 0 symbol in front of the field width.

For example:

printf("%05d",20);

Result:
00020

In addition to data format specifiers, the control line may contain control characters:

\b BS, bottom
\f New page, page change
\n New line, line feed
\r Carriage return
\t Horizontal tabulation
\v Vertical tab
\" Double quote
\" Apostrophe
\\ Backslash
\0 Null character, null byte
\a Signal
\N Octal constant
\xN Hexadecimal constant
\? Question mark

Most often you will use the \n character. With this control character you can go to a new line. Look at the example programs and you will understand everything.

Examples of programs.

/* Example 1 */
#include

void main(void)
{
int a,b,c; // Announcement variables a,b,c
a=5;
b=6;
c=9;
printf("a=%d, b=%d, c=%d",a,b,c);
}

Result of the program:
a=5, b=6, c=9

/* Example 2 */
#include

void main(void)
{
float x,y,z;

X=10.5;
y=130.67;
z=54;

Printf("Object coordinates: x:%.2f, y:%.2f, z:%.2f", x, y, z);
}

Result of the program:
Object coordinates: x:10.50, y:130.67, z:54.00

/* Example 3 */
#include

void main()
{
int x;

X=5;
printf("x=%d", x*2);
}

Result of the program:
x=10

/* Example 4 */
#include

void main(void)
{
printf("\"Text in quotes\"");
printf("\nOxygen content: 100%%");
}

Result of the program:
"Text in quotes"
Oxygen content: 100%

/* Example 5 */
#include

void main(void)
{
int a;

A=11; // 11 in decimal is equal to b in hexadecimal
printf("a-dec=%d, a-hex=%X",a,a);
}

Result of the program:
a-dec=11, a-hex=b

/* Example 6 */
#include

void main(void)
{
char ch1,ch2,ch3;

Ch1="A";
ch2="B";
ch3="C";

Printf("%c%c%c",ch1,ch2,ch3);
}

Result of the program:
ABC

/* Example 7 */
#include

void main(void)
{
char *str="My string.";

Printf("This is %s",str);
}

Result of the program:
This is My line.

/* Example 8 */
#include

void main(void)
{
printf("Hello!\n"); // After printing there will be a transition to a new line - \n
printf("My name is Pavel."); // This will be printed on a new line
}

Result of the program:
Hello!
My name is Pavel.

The standard input function scanf()

The scanf() function is a formatted input function. With its help, you can enter data from a standard input device (keyboard). Input data can be integers, floating point numbers, characters, strings, and pointers.

The scanf() function has the following prototype in stdio.h:
int scanf(char *control string);

The function returns the number of variables that have been assigned a value.

The control string contains three types of characters: format specifiers, spaces, and other characters. Format specifiers begin with the % character.

Format specifiers:

When entering a string using the scanf() function (%s format specifier), the string is entered before the first space!! those. if you enter the string "Hello world!" using scanf() function


scanf("%s",str);

then after entering the resulting string, which will be stored in the str array, will consist of one word “Hello”. THE FUNCTION ENTERS A STRING BEFORE THE FIRST SPACE! If you want to enter strings with spaces, then use the function

char *gets(char *buf);

With the gets() function you can enter full strings. The gets() function reads characters from the keyboard until the newline character (\n) appears. The newline character itself appears when you press enter. The function returns a pointer to buf. buf - buffer (memory) for the input string.

Although gets() is not the topic of this article, let's write an example program that allows you to enter an entire line from the keyboard and display it on the screen.

#include

void main(void)
{
char buffer; // array (buffer) for the input string

Gets(buffer); // enter a line and press enter
printf("%s",buffer); // output the entered string to the screen
}

One more important note! To enter data using the scanf() function, it needs to pass variable addresses as parameters, not the variables themselves. To get the address of a variable, you need to precede the variable name with an & (ampersand). The & sign means taking the address.

What does address mean? I'll try to explain. In the program we have a variable. A variable stores its value in computer memory. So this is the address that we get using & is the address in the computer memory where the value of the variable is stored.

Let's look at an example program that shows us how to use &

#include

void main(void)
{
int x;

Printf("Enter variable x:");
scanf("%d",&x);
printf("Variable x=%d",x);
}

Now let's return to the control line of the scanf() function. Again:

int scanf(char *control string);

The space character on the control string commands one or more spaces to be skipped in the input stream. In addition to the space, a tab or newline character can be perceived. A non-null character indicates that the character is read and discarded.

The separators between the two numbers you enter are space, tab, or newline. The * sign after % and before the format code (format specifier) ​​gives the command to read the data specified type, but do not assign this value.

For example:

scanf("%d%*c%d",&i,&j);

entering 50+20 will set variable i to 50, variable j to 20, and the + character will be read and ignored.

The format command can specify the largest field width to be read.

For example:

scanf("%5s",str);

indicates the need to read the first 5 characters from the input stream. If you enter 1234567890ABC, the str array will only contain 12345, the remaining characters will be ignored. Separators: space, tab and newline - when entering a symbol, they are treated like all other characters.

If any other characters occur in the control string, they are intended to identify and skip the corresponding character. Character stream 10plus20 operator

scanf("%dplus%d",&x,&y);

will assign the value 10 to the variable x, the value 20 to the variable y, and will skip the plus characters because they occur in the control string.

One of the powerful features of the scanf() function is its ability to specify a scanset. The search set defines the set of characters with which the characters read by the scanf() function will be compared. The scanf() function reads characters as long as they appear in the search set. As soon as the character that is entered is not found in the search set, the scanf() function moves to the next format specifier. The search set is determined by the list of symbols enclosed in square brackets. The % sign is placed before the opening bracket. Let's look at this with an example.

#include

void main(void)
{
char str1, str2;
scanf("%%s", str1, str2);
printf("\n%s\n%s",str1,str2);
}
Let's enter a set of characters:
12345abcdefg456

The program will display on the screen:
12345
abcdefg456

When specifying a search set, you can also use the hyphen character to specify spacing, as well as the maximum width of the input field.

scanf("%10", str1);

You can also define characters that are not included in the search set. The first of these characters is preceded by a ^. Many characters differentiate between lowercase and uppercase letters.

Let me remind you that when using the scanf() function, it needs to pass variable addresses as parameters. The code above was written:

char str; // array of 80 characters
scanf("%s",str);

Note that str is not preceded by &. This is done because str is an array and the array name - str is a pointer to the first element of the array. Therefore, the & sign should not be used. We already pass the address to the scanf() function. Well, simply put, str is the address in computer memory where the value of the first element of the array will be stored.

Examples of programs.

Example 1.
This program displays the request "How old are you?:" and waits for data input. If, for example, you enter the number 20, the program will display the line “You are 20 years old.”. When calling the scanf() function, we put an & sign in front of the age variable, since the scanf() function needs variable addresses. The scanf() function will write the entered value to the specified address. In our case, the entered value 20 will be written to the address of the age variable.

/* Example 1 */

#include

void main(void)
{
int age;

Printf("\nHow old are you?:");
scanf("%d",&age);
printf("You are %d years old.", age);
}

Example 2.
Calculator program. This calculator can only add numbers. When you enter 100+34, the program will produce the result: 100+34=134.

/* Example 2 */

#include

void main(void)
{
int x, y;

Printf("\nCalculator:");
scanf("%d+%d", &x, &y);
printf("\n%d+%d=%d", x, y, x+y);
}

Example 3.
This example shows how to set the reading field width. In our example, the field width is five characters. If you enter a string with a large number of characters, then all characters after the 5th will be discarded. Notice the scanf() function call. The & sign does not precede the array name name because the array name name is the address of the first element of the array.

/* Example 3 */

#include

void main(void)
{
char name;

Printf("\nEnter your username (no more than 5 characters):");
scanf("%5s", name);
printf("\nYou entered %s", name);
}

Example 4.
The last example in this article shows how a search set can be used. After starting the program, enter a number from 2 to 5.

/* Example 4 */

#include

void main(void)
{
char bal;

Printf("Your rating is 2,3,4,5:");
scanf("%", &bal);
printf("\nRating %c", bal);
}

This article discusses the scanf() function in a general way without reference to a specific standard, so data from any C99, C11, C++11, C++14 standards is included here. It is possible that in some standards the function works differently from the material presented in the article.

scanf C function - description

scanf() is a function located in the header file of stdio.h(C) and cstdio(C++), it is also called formatted input to the program. scanf reads characters from standard input (stdin) and converts them according to the format, then writes them to the specified variables. Format means that the data, when received, is reduced to a certain form. Thus, the scanf C function is described:

scanf("%format", &variable1[, &variable2,[…]]),

where variables are passed as addresses. The reason for passing variables to a function this way is obvious: as a result of its operation, it returns a value indicating the presence of errors, so the only way to change the values ​​of variables is to pass by address. Also, thanks to this method, the function can process data of any type.

Some programmers call functions like scanf() or printf() procedures because of analogies with other languages.

Scanf allows you to enter all basic language types: char, int, float, string, etc. In the case of variables of type string, there is no need to indicate the address sign - “&”, since a variable of type string is an array, and its name is the address of the first element of the array in the computer memory.

Data input format or control string

Let's start by looking at an example of using the scanf C function from the description.

#include int main() ( int x; while (scanf("%d", &x) == 1) printf("%d\n", x); return 0; //requirement for linux systems )

The input format consists of the following four parameters: %[*][width][modifiers] type. In this case, the “%” sign and type are required parameters. That is, the minimum format looks like this: “%s”, “%d” and so on.

In general, the characters that make up a format string are divided into:

  • format specifiers - everything that begins with the % symbol;
  • separating or whitespace characters - these include space, tab (\t), new line (\n);
  • characters other than whitespace.

The function may be unsafe.

Use scanf_s() instead of scanf().

(posted by Visual Studio)

Type, or format specifiers, or conversion characters, or control characters

The description of scanf C must contain, at a minimum, a format specifier, which is indicated at the end of expressions beginning with the "%" sign. It tells the program the type of data to expect upon input, usually from the keyboard. A list of all format specifiers is in the table below.

Meaning

The program waits for a character to be entered. The variable to be written must be of character type char.

The program is waiting for input decimal number a whole type. The variable must be of type int.

The program expects a floating point number in exponential form. The variable must be of type float.

The program expects a floating point number to be entered. The variable must be of type float.

7

The program expects a floating point number to be entered. The variable must be of type float.

The program expects an octal number to be entered. The variable must be of type int.

The program expects a string to be entered. A string is considered to be a set of any characters up to the first delimiter character encountered. The variable must be of type string.

The program is waiting for input hexadecimal number. The variable must be of type int.

The variable expects a pointer input. The variable must be a pointer type.

Writes an integer value to a variable equal to the number of characters read so far by the scanf function.

The program reads an unsigned integer. The variable type must be unsigned integer.

The program expects a binary number to be entered. The variable must be of type int.

A set of scannable characters. The program waits for input of characters from a limited pool specified between scanf and will work as long as there are characters from the specified set on the input stream.

Characters in the format string

Asterisk (*)

The asterisk (*) is a flag indicating that the assignment operation should be suppressed. An asterisk is placed immediately after the “%” sign. For example,

Scanf("%d%*c%d", &x, &y); //ignore the character between two integers. scanf("%s%*d%s", str, str2); //ignore the integer between two strings.

That is, if you enter the line “45-20” in the console, the program will do the following:

  1. The variable "x" will be assigned the value 45.
  2. The variable "y" will be assigned the value 20.
  3. And the minus sign (dash) “-” will be ignored thanks to “%*c”.

Width (or field width)

This is an integer between the "%" sign and the format specifier that specifies the maximum number of characters to read during the current read operation.

There are a few important points to keep in mind:

  1. scanf will stop running if it encounters a delimiter character, even if it hasn't counted 20 characters.
  2. If the input contains more than 20 characters, only the first 20 of them will be written to the str variable.

Type modifiers (or precision)

These are special flags that modify the type of data expected for input. The flag is specified to the left of the type specifier:

  • L or l (small L) When using "l" with the specifiers d, i, o, u, x, the flag tells the program to expect input of type long int. When using "l" with the e or f specifier, the flag tells the program that it should expect input of type double. Using "L" tells the program that a value of type long double is expected. Using "l" with the "c" and "s" specifiers tells the program that double-byte characters of type wchar_t are expected. For example, "%lc", "%ls", "%l".
  • h is a flag indicating the type short.
  • hh - indicates that the variable is a pointer to a value of type signed char or unsigned char. The flag can be used with the specifiers d, i, o, u, x, n.
  • ll (two small L) - indicates that the variable is a pointer to a value of type signed int or unsigned long long int. The flag is used with the specifiers: d, i, o, u, x, n.
  • j - denotes that the variable is a pointer to type intmax_t or uintmax_t from the stdint.h header file. Used with specifiers: d, i, o, u, x, n.
  • z - denotes that the variable is a pointer to type size_t, the definition of which is in stddef.h. Used with specifiers: d, i, o, u, x, n.
  • t - denotes that the variable is a pointer to type ptrdiff_t. The definition for this type is in stddef.h. Used with specifiers: d, i, o, u, x, n.

The picture with modifiers can be more clearly presented in the form of a table. This description of scanf C will be clearer for programmers.

Other characters

Any characters encountered in the format will be discarded. It is worth noting that the presence of whitespace or delimiting characters (newline, space, tab) in the control string can lead to different behavior of the function. In one version, scanf() will read without saving any number of delimiters until it encounters a character other than the delimiter, and in another version, spaces (only they) do not matter and the expression "%d + %d" is equivalent to "% d+%d".

Examples

Let's look at a number of examples to help you think about and more accurately understand how the function works.

Scanf("%3s", str); //if you enter the line “1d2s3d1;3” in the console, only “1d2” will be written to str scanf("%dminus%d", &x, &y); //minus characters between two numbers will be discarded scanf("%5", str); //characters will be entered into str until there are 5 of them and the characters are numbers from 0 to 9. scanf("%lf", &d); //expected input of type double scanf("%hd", &x); //expect a number of type short scanf("%hu", &y); //expect a number of type unsigned short scanf("lx", &z); //expected number of type long int

From the examples given you can see how the expected number changes using different symbols.

scanf C - description for beginners

This section will be useful for beginners. Often you need to have on hand not so much full description scanf C, how many details of how the function works.

  • The function is somewhat obsolete. There are several different implementations in libraries of different versions. For example, the improved scanf S C function, a description of which can be found on the Microsoft website.
  • The number of specifiers in the format must correspond to the number of arguments passed to the function.
  • Elements of the input stream must be separated only by delimiting characters: space, tab, newline. Comma, semicolon, period, etc. - these characters are not delimiters for the scanf() function.
  • If scanf encounters a delimiter character, input will be stopped. If there is more than one variable to read, scanf will move on to reading the next variable.
  • The slightest discrepancy in the format of the input data leads to unpredictable results of the program. It's good if the program just ends with an error. But often the program continues to work and does it incorrectly.
  • scanf("%20s ...", ...); If the input stream exceeds 20 characters, scanf will read the first 20 characters and either terminate or move on to read the next variable, if specified. The next scanf call will continue reading the input stream from where the previous scanf call left off. If a delimiter character is encountered while reading the first 20 characters, scanf will stop working or move on to reading the next variable, even if it did not read 20 characters for the first variable. In this case, all uncounted characters will be attached to the next variable.
  • If the set of characters to be scanned begins with the "^" sign, then scanf will read the data until it encounters a delimiter character or a character from the set. For example, "%[^A-E1-5]" will read data from the stream until one of the uppercase English characters A through E or one of the numbers 1 through 5 is encountered.
  • The scanf C function, as described, returns a number equal to the successful number of entries into variables. If scanf writes 3 variables, then the result of the successful operation of the function will be the return of the number 3. If scanf could not write any variables, then the result will be 0. And finally, if scanf could not start working at all for some reason, the result will be EOF .
  • If the scanf() function did not complete its work correctly. For example, scanf("%d", &x) - a number was expected, but symbols were received as input. The next scanf() call will start from the point in the input stream where the previous function call ended. To overcome this problem, you need to get rid of the problematic characters. This can be done, for example, by calling scanf("%*s"). That is, the function will read a string of characters and throw it away. In this clever way, you can continue entering the required data.
  • Some implementations of scanf() do not allow the use of "-" in the character set to be scanned.
  • The “%c” specifier reads each character from the stream. That is, it also reads the delimiter character. To skip the delimiter character and continue reading the desired character, you can use “%1s”.
  • When using the “c” specifier, it is acceptable to use the width “%10c”, but then in the form variable function scanf you need to pass an array of char type elements.
  • “%” means “all small letters of the English alphabet”, and “%” simply means 3 characters: ‘z’, ‘a’, ‘-’. In other words, the "-" character only means a range if it appears between two characters that are in the correct order. If "-" is at the end of an expression, at the beginning, or in the wrong order of characters on either side of it, then it simply represents a hyphen character, not a range.

Conclusion

This concludes the description of scanf C. It is a good convenience function for working in small programs and when using the procedural programming method. However, the main drawback is the number of unpredictable errors that can occur when using scanf. Therefore, it is best to keep the description of scanf C before your eyes when programming. In large professional projects, iostreams are used due to the fact that they have higher-level capabilities, are better able to catch and process errors, and also work with significant amounts of information. It should also be noted that a description of scanf C in Russian is available on many online sources, as well as examples of its use, due to the age of the function. Therefore, if necessary, you can always find the answer on thematic forums.

Computers are perhaps the most versatile tools that humanity has at its disposal. They are capable of performing incredible calculations, they allow you to store a huge amount of information, completely different parts of the planet, and at the same time easily exchange it, regardless of location. Computers make many everyday tasks easier, and they make it possible to automate many routine processes that would be very tedious and boring for a human to do. There are so many things that computers can do, but nevertheless, computers do not have intelligence, unlike humans. To automate even the simplest process, you need to tell the computer clearly and unambiguously what it should do. Unfortunately, our language and the computer language are completely different. Thus, between a machine and a person there is a serious language barrier that must be overcome somehow, otherwise the computer will not understand us. And as long as computers don’t understand us, they won’t do anything on their own. A huge number of programming languages ​​have been invented as a means of communication between a person and a computer. With the help of programming languages, we create programs and the computer directly works with the programs. Programs themselves are sets of instructions that a computer can understand and execute.

Types of programs

In order to communicate effectively with the computer, which is what we want, there is a wide range of programming languages.

Depending on the type of project, there are many factors to consider when choosing a programming language. Here is a list of the most notable factors:

Compilation, interpretation and JIT compilation

The compilation process translates code written in a programming language into native language target machine. The program that performs this process is called a compiler. Compilation can make the code run quite quickly, especially if the compiler is efficient at optimizing. But the fact is that the resulting code cannot work on different operating systems, and the compilation process takes some time, and the more code, the longer process compilation. It is worth noting that when making any changes to the program code, it is necessary to compile it and only then run it.

Interpreted programming languages ​​are read by a program called an interpreter and executed by the same program. Interpreted programming languages ​​can run on different operating systems, just like an interpreter, and do not even have long compilation times. But programs written using interpreted languages ​​tend to run much slower than equivalent, compiled programs.

And finally, the so-called on-the-fly compilation (or JIT compilation). Such languages ​​are quickly compiled at the time the program is launched. Programs written in JIT languages, as a rule, are not optimized, thereby speeding up the compilation process and restoring the balance between performance and cross-platform compatibility.

High or low programming levels

Low-level languages ​​mostly work directly with hardware, and are therefore best suited for writing device drivers. Drivers are programs that control hardware and have direct access to it. However, a program written in the language low level, tends to be difficult to port to other platforms. And therefore, for each OS, the same device comes with different drivers. Low-level programming languages ​​almost always compile.

In high-level languages, the entire focus is on the concept of language. That is, such a programming language should be easy to understand, such as representing data as arrays, strings, objects, etc. A high-level language is usually easier to understand than a low-level language. And, as a rule, developing a program in a high-level language is much easier and faster than in a low-level language. As you can see, different levels of programming are intended for completely different tasks, and you should not compare the functionality of languages ​​at different levels, it is pointless.

Programming Language Data Type Systems

For every programming language, there is a specification that defines various rules that programming languages ​​must follow. Some languages ​​don't have data types, so this doesn't apply to them. However, most languages ​​(including C++) have data types, so this information will be useful to you.

Strong or weak data type system

A weak input system does not impose any restrictions; the programmer must monitor this. When I say “weak data system,” I mean that a language with such a data system does not strictly regulate the available data type casts. For example, if you pass a string or symbol instead of a number to the multiplication function, non-strictly typed programming languages ​​will execute such code, although the result of the multiplication loses all meaning, since a string cannot be multiplied by a number. Moreover, the result of performing this meaningless multiplication will be unpredictable. If the programming language is strictly typed, then at the compilation stage, the translator will report an error and stop the process of building the project. For example,

// example program in C++ #include using namespace std; int main())( char string = "example"; int number = 5; cout<< string * number << endl; // умножаем строку на число }

As a result, the compiler will report an error:

error: invalid operands of types ‘char ’ and ‘int’ to binary ‘operator*’

We will try to do the same in a non-strongly typed programming language - php. Please note that even when declaring variables, you do not need to specify the data type.

The result of executing this code will be zero. No error will occur, although it would seem that you cannot multiply a string by a number. But in PHP everything is possible. The PHP language compiler will not report an error, the script will work and even produce the result, and if our program consists of 1000 lines of code, then it will be difficult for us to find this error. This is a striking example of a programming language with a “weak data type system,” that is, preventing such absurd operations rests entirely on the shoulders of the programmer.

Defined or undefined data type

This applies to both compiled and interpreted languages. Many languages ​​require an explicit definition of the type of variables, so there is no uncertainty, the compiler and interpreter clearly know what to do. Some programming languages ​​do not require explicit definition of the type of variables. The data type is determined automatically based on the contents of the variable.

Static or dynamic data type

If the language is statically typed, then the compiler/interpreter does type checking once before the compilation/interpretation process. If the data type is dynamic, then the data types are checked at run time.

Safe or unsafe data type system

There may be situations that may lead to unexpected results or errors. A safe language will introduce as many restrictions as possible to ensure that such situations do not arise. While an unsafe language places all responsibility on the programmer.

These factors can characterize either one or several programming languages.

Supported programming paradigms

Programming paradigms are methodologies or ways of programming that a programming language supports. Here is a list of the main paradigms:

Declarative paradigm

A declarative programming language will place more emphasis on the goal rather than the means to achieve that goal. It is enough to indicate what needs to be achieved, but it is not necessary to indicate what means to use. This paradigm prevents unwanted side effects that can occur when writing your own code.

Functional paradigm

Functional programming is a subset of declarative programming that attempts to solve problems in terms of mathematical equations and functions. Functional programming treats variables and objects as data that is not shared, unlike imperative languages.

Generalized paradigm

Generic programming focuses on writing algorithms in terms of data types to be defined. That is, the same algorithm can work with different types of data. This approach can be a very powerful tool, but only if implemented well.

Imperative paradigm

Imperative languages ​​allow programmers to give the computer an ordered list of instructions that are needed to complete a task. Imperative programming languages ​​are contrasted with declarative programming languages.

Structural paradigm

Structural programming languages ​​aim to provide some form of code—a hierarchical structure. When the structure of the code is clearly visible, the order in which the statements are executed becomes intuitively clear. Such languages ​​usually discourage “jumping” from one part of the code to another, for example, the goto operator we all know, which is defined in the C and C++ languages.

Procedural paradigm

Procedural programming language refers to structured programming languages ​​that support the concept of procedure or subroutine.

Object-oriented paradigm

Object-oriented programming (sometimes abbreviated OOP) is a subset of structured programming that expresses programs in terms of "objects". This paradigm allows code to be reused, and this approach is quite simple to understand.

Standardization

Do languages ​​have an official standard? Standardization is very important to ensure conflict-free understanding of the program by different compilers/interpreters. Some languages ​​are standardized by the American National Standards Institute (ANSI), others are standardized by the International Organization for Standardization (ISO). All programming languages ​​must be standardized, otherwise there will be no agreement on what is correct and incorrect in syntax.

Let's characterize the C++ programming language

Now that we have examined the main characteristics of programming languages, let us determine which factors the C++ programming language satisfies.

C++ is an ISO standardized programming language.

For some time, C++ did not have an official standard, however, since 1998, C++ has been standardized by an ISO committee.

C++ compiled language.

C++ compiles directly to machine code, making it one of the world's fastest languages.

C++ is a strongly typed language.

C++ assumes that the programmer knows what he is doing, and allows an incredible number of possibilities, limited only by imagination.

C++ supports static and dynamic data types.

Thus, data type checking can be done at compile time or at run time. And this once again proves the flexibility of C++.

C++ supports many paradigms.

C++ supports procedural, generic, and object-oriented programming paradigms, and many other paradigms.

C++ is a portable programming language.

As one of the most commonly used languages ​​in the world, and as an open language, C++ has a wide range of compilers that run on a variety of platforms. The C++ Standard Library code will run on many platforms.

C++ is fully compatible with the C language

In C++ you can use C libraries and they will work properly.


Close