the Internet Windows Android

SI programming language. C (SI) programming language

These learning lessons are designed for everyone, regardless of whether you are in programming or you already have extensive programming experience in other languages! This material for those who want to explore the C / C ++ languages \u200b\u200bfrom its most difficult structures.

C ++ is a programming language, the knowledge of this programming language will allow you to manage your computer at the highest level. Ideally, you can make the computer do everything you want. Our site will help you in mastering the C ++ programming language.

Installation / IDE

The very first thing you should do before proceeding with learning C ++, it is to make sure that you have an IDE - an integrated development environment (the program in which you will program). If you do not have an IDE, then you here. When decide on the IDE selection, install it and practice creating simple projects.

Introduction to C ++ language

C ++ language is a set of commands that the computer says what needs to be done. This set of commands is usually called source or just code. Commands are or "functions" or " keywords" Keywords (reserved words C / C ++) are the main building blocks of the language. Functions are complex building blocks, as they are recorded in terms of simpler functions - you will see this in our most first program, which is shown below. Such a structure of functions resembles the content of the book. The content can show the heads of the book, each chapter in the book can have its own content consisting of items, each item can have its sub-clauses. Although C ++ provides many common functions and reserved words that you can use, still the need arises in writing its own functions.

In what part of the program began? Each program in C ++ has one function, it is called the main or main function, the execution of the program begins with this function. Of main functionYou can also call any other functions, it does not matter whether they are written by us, or, as mentioned earlier, are provided by the compiler.

So how do you get access to these standard functions? To access the standard functions that are supplied with the compiler, you must connect the header file using the preprocessor directive - #InClude. Why is it effective? Let's look at the example work program:

#Include. << "Моя первая программа на С++\n"; cin.get(); }

Consider in detail the elements of the program. #include is a preprocessor directive that tells the compiler to put the code from the iOSTream header file in our program before creating an executable file. By connecting the header file to the program you get access to a variety of different functions that can be used in your program. For example, an iOSTREAM operator is required. String using Namespace STD; Informs the compiler that you need to use a group of functions that are part of the standard STD library. Including this string allows the program to use operators, such as COUT. A semicolon is part of C ++ syntax. She informs the compiler that this is the end of the team. A little later you will see that a comma point is used to complete the majority of commands in C ++.

Next important line of the int major program (). This line reports the compiler that there is a function named Main, and that the function returns an integer type of int. Figure brackets (s) sign up to the beginning (and end) function. Figured brackets are used in other code blocks, but always one - the beginning and end of the block, respectively.

In C ++, the COUT object is used to display text (pronounced as "Cy Out"). It uses symbols<< , известные как «оператор сдвига», чтобы указать, что отправляется к выводу на экран. Результатом вызова функции cout << является отображение текста на экране. Последовательность \n фактически рассматривается как единый символ, который обозначает новую строку (мы поговорим об этом позже более подробно). Символ \n перемещает курсор на экране на следующую строку. Опять же, обратите внимание на точку с запятой, её добавляют в конец, после каждого оператора С++.

Next command cin.get (). This is another call to the function that reads data from the data stream and expects the Enter key. This command saves the console window from the closure, until the Enter key is pressed. It gives you the time to see the result of the program.

Upon reaching the end of the main function (closing curry bracket), our program will return the value 0 for the operating system. This return value is important, since, after analyzing it, the OS may judge whether our program has successfully completed or not. Return value 0 means success and returns automatically (but only for Int data type, other functions are required to manually return the value), but if we wanted to return something else, for example, 1, we would have to do it manually.

#Include. Using Namespace STD; INT MAIN () (COUT<<"Моя первая программа на С++\n"; cin.get(); return 1; }

To secure the material, type the program code in your IDE and run it. After the program has started, and you have seen the result of the work, experiment a little with the COUT operator. This will help you get used to the language.

Be sure to comment on your programs!

Add comments to the code to make it clearer not only for yourself but also for others. The compiler ignores comments when performing code, which allows you to use any number of comments to describe the real code. To create a comment, use or //, which tells the compiler that the rest of the line is a comment or / * and then * /. When you learn to program, it is useful to be able to comment on some sections of the code in order to see how the result of the program is changed. Read more about commenting techniques, you can.

What to do with all these types of variables?

Sometimes it can confuse - have several types of variables when it seems that some types of variables are redundant. It is very important to use the correct type of variable, as some variables required more memory than others. In addition, due to the storage method in memory, the floating point number, the data types of float and doubles are "inaccurate", and should not be used when it is necessary to maintain accurately value.

C ++ variables announcement

To declare a variable used syntax type<имя>; . Here are some examples of variable ads:

Int num; char character; Float num_float;

It is permissible to declare several variables of the same type in one line, for this each of them must be separated.

Int x, y, z, d;

If you looked carefully, you may have seen that the declaration of the variable is always accompanied by a semicolon. More information about the agreement is "On Naming Variables", you can.

Common Errors when declaring variables in C ++

If you try to use the variable that you did not declare, your program will not be compiled, and you will receive an error message. In C ++, all keywords of the language, all functions and all variables are sensitive to the register.

Using variables

So, now you know how to declare a variable. Here is an example of a program demonstrating the use of the variable:

#Include. Using Namespace STD; INT MAIN () (Int Number; Cout<< "Введите число: "; cin >\u003e Number; cin.ignore (); Cout<< "Вы ввели: "<< number <<"\n"; cin.get(); }

Let's look at this program and study its code, string per line. The Inta keyword suggests that Number is an integer. The CIN function \u003e\u003e reads the value to Number, the user must press input after the entered number. cin.ignore () is a function that reads the character and ignore it. We organized our input to the program after entering the number, we press the Enter key, the symbol that is also transmitted to the input stream. We do not need it, so we throw it away. Keep in mind that the variable was declared a whole type if the user tries to enter a decimal number, then it will be cropped (that is, the decimal part of the number will be ignored). Try entering a decimal number or sequence of characters when you run an example of a program, the answer will depend on the input value.

Please note that when printing from variable quotes are not used. The absence of quotes informs the compiler that there is a variable, and, therefore, that the program must check the value of the variable in order to replace the name of the variable to its value when execution. Several shift operators in one line are quite acceptable and the output will be performed in the same order. You must share string literal literals (lines enclosed in quotes) and variables, giving each shift operator to each<< . Попытка поставить две переменные вместе с одним оператором сдвига << выдаст сообщение об ошибке . Не забудьте поставить точку с запятой. Если вы забыли про точку с запятой, компилятор выдаст вам сообщение об ошибке при попытке скомпилировать программу.

Change and comparison of values

Of course, no matter what type of data you use, the variables do not represent much interest without the possibility of changing their value. The following shows some operators used in conjunction with variables:

  • * multiplication,
  • - subtraction,
  • + addition
  • / division,
  • \u003d assignment,
  • \u003d\u003d equality,
  • \u003e More
  • < меньше.
  • ! \u003d Neoquins
  • \u003e \u003d more or equal
  • <= меньше или равно

Operators that perform mathematical functions should be used to the right of the assignment mark, in order to assign the result of the variable to the left.

Here are some examples:

A \u003d 4 * 6; // Using a line comment and a semicolon, a equal to 24 a \u003d a + 5; // Equally the amount of the source value and five a \u003d\u003d 5 // is not assigned five, checking is performed, as well as 5 or no

You will often use \u003d\u003d in structures such as conditional operators and cycles.

A.< 5 // Проверка, a менее пяти? a > 5 // Check, a more than five? a \u003d\u003d 5 // Check, A is five? a! \u003d 5 // Check, and unequal and five? A\u003e \u003d 5 // Check, A more than or equal to five? A.<= 5 // Проверка, a меньше или равно пяти?

These examples are not very clearly showing the use of comparison signs, but when we start studying the selection operators, you will understand why it is necessary.

Select the lessons you are interested in:

C is a programming language that was created in 1972 Dennis M. Ritchi. The standard of the language of that time was demonstrated in the book of Rietch in collaboration with Brian Kernigan ("SI programming language"). This standard is called K & R standard (by the names of Kernigan and Ritchch). Any program written using the K & R rules is successfully compiled by any C compiler.

Programmers developing compilers for C began to upgrade and develop language. In order not to be confused, the American Institute of National Standards (American National Standards Institute) in 1983 developed an ANSI standard. ANSI-SI and to this day establishes the rules for the change and development of the SI language.

C - programming language compiled. The program provides instructions and functions that, to perform their hardware, the computer must be translated into binary codes.
Si is quite popular and at present, this is due to such in demand by its qualities, like: speed, tolerability and structuring.

  • Speed

Among all the high-level languages \u200b\u200bare a programming language that is closer to the assembler. So, many language instructions are addressed directly to the hardware of the computer, which is why the program is performed very quickly. For this reason, C can be used to write operating systems and compilers.

Most of the used SI compilers generate highly optimized codes, i.e. Simply put, small in size (the smaller the code generates the compiler, the more optimized it is).

  • Portability

In principle, it would be reasonable to write fast-running programs on the assembler. But they would have to write them under each platform, since mnemonic assembler codes were adapted under the family of microprocessors.

SI uses standard keyword sets. Those. The program is written once for any platform, any computer with any operating system. But the compilers for the language are two types: Some for IBM, others - for Apple. But the text of the program itself is created once and for all.

  • Structuring

Programs written in C language have their own structure and rules that encourages the programmer to think logically.
The need to structuring the program is only a "plus", because it is thanks to this program on Si it is very easy to design, maintain and debug.

  • Libraries features

C - programming language, initially containing a small amount of operations in its syntax. For example, the language does not have embedded input and output operators, as well as operators to work with lines.

All SI features are provided by the libraries of functions, some of which are supplied with the compiler. The library is a separate file attached to the compiler and containing functions to solve specific tasks.

C programming language (it is necessary to pronounce "SI") can be described as universal, economical, with a full set of operators, with modern and flow control. This language cannot be called "big" language, he also does not claim the title of "high-level language", he was not created for some specific tasks, on the contrary, they tried to make the most effective for any applications. This interesting alloy of ideas invested in C programming language made it very convenient and more efficient for a wide range of problems than others perhaps even more advanced languages.

The connection "C" from the UNIX OS is very close, since this language developed together with "Unix" and most of the software for this system is written on it. At the same time, with sometimes called the language as it is believed that it is believed that it is convenient to create operating systems, in fact, with the same success on it, it is written database processing programs and games.

C is a low-level programming language, but it should not be considered that it is bad, in fact, it simply operates with the same objects that any computer constantly work with symbols, addresses and numbers. In this case, all objects are combined, compared or subtracted using conventional logical and arithmetic actions familiar to computer.

Although the functions of working with composite objects are becoming the norm in the world of coding and embed them into all modern programming languages, C, unlike others, does not know how to work with such objects as a string, a list, array or set. There are no analogues of PL / 1 operations over whole lines and arrays.

With memory with working with a stack and statistical definition, other possibilities of operating memory with does not have, you will not find a "bunch" (HEAP) or "garbage cleaning", as Pascal or Algol 68 can do it.

And even the most basic mechanisms, I / O, the language with does not provide, read and write statements you will not find in it, there are also no embedded functions of working with the file system. Such high-level operations are provided using connected libraries.

And the programming language C will refuse to work if you need multiprogramming, synchronization, parallel operations, etc. It contains opportunities exclusively for simple and consistent work, his element: cycles, checks, grouping and subroutine.

Someone may surprise such a misfortune of funds provided by programmers, ("Why should I call a function every time I need to compare a couple of lines!"), But on the other hand, it is thanks to such savings, programs written on C, Real advantage in speed.

On the other hand, a small number of operators reduces the time required to memorize them, and you have enough multiple pages to describe them all. And as practice shows, the compiler with "C" is a compact tool that is easy enough to write. If you use modern means, the compiler for a completely new computer will be ready in just a couple of months, despite the fact that 80% of its code will be similar to the code of previous versions. Thanks to such a feature, the programming language C is considered very mobile. Yes, and its effectiveness is such that to write on assembler any programs that are critical to performance, as it was accepted earlier, it simply does not make sense. The best example of this is the UNIX OS itself, which is 90% written on "C" and for it, almost completely created by numerous programmers in the same wonderful language, which is currently considered in the world of programming language number one.

practical course

What it is?

At one time (1991-1992), choosing a language S. As the main programming language for mathematical classes, the author faced the problem of the lack of normal textbooks that can be recommended to schoolchildren. It forced him to write his abstract lectures, which could be called "A practical programming course on S.» - It includes those information that was really required to the author in practice. Many years of teaching experience has shown that the abstract is really in demand and is widely used both schoolchildren and graduates.

As a development environment, a free distributed Open source DEV-C ++ sheath is used, including the GCC compiler.

The author will be grateful for feedback and constructive criticism about the content and design of these materials. If you notice a mistake or you have suggestions, comments, complaints, requests and applications, write.

License agreement

  1. 1) Publication of materials in any form, including the placement of materials on other Web sites;
  2. 2) the distribution of incomplete or modified materials;
  3. 3) the inclusion of materials into collections on any media;
  4. 4) Obtaining commercial benefits from the sale or other use of materials.

Downloading materials means that you have taken the terms of this license agreement.

Download

The abstract extends freely in format PDF.. You need a free Acrobat Reader Reseller. The abstract of the course is conditionally divided into 4 parts:

  1. Introduction to Programming in SI (860 KB) 29.03.2014
    Studying the main designs of the program language and techniques.
  2. Storage and processing of data (792 KB) 21.11.2013
    SI language: arrays, matrices, structures, character strings, structures, recursion.
  3. Development of programs in SI (937 KB) 01.03.2014
    Program design methods, structural programming, integer algorithms, numerical methods, modeling.
  4. Dynamic data structures in SI (666 KB) 11.06.2009
    Lists, stacks, trees, graphs.

Presentations

For teachers and students, presentations built on the basis of this abstract may be useful. You can download them on the Presentation page.

Methodik

The main task is to introduce students with the basic designs of the language S.: cycles, conditional operators, procedures. It is very successfully the study of sections associated with graphics, animation.

To work with graphics through the browser, you can use the online service of Anton Denikin.

8th grade

The program includes the following sections (part of the abstract is indicated in brackets): Arrays (II), Working with Files (II), Symbolic Lines (II), Rotation of Objects (III), Modeling (III). Particular attention is paid to the study of algorithms for working with arrays, including search, sorting, etc. The concept of the effectiveness of computational methods is given.

Grade 9.

The focus is on learning program development methods in language S.. Students perform an individual task, during which they study graphs on the screen, get acquainted with the transformations of coordinate systems, study the methods of solving equations, get acquainted with numerical methods, learn to correctly execute programs (partitions 1-2 of Part III). One of the tasks is devoted to the use method Monte Carlo To calculate the area of \u200b\u200ba complex figure. From new sections are also studied Matrix (II), arrays of character strings (II). The concept is introduced pointers And the simplest operations with them are being studied.

Grade 10

Learning language S. It turns out a more serious level. Main topics - Memory Management (II), Recursion (II), Structures (II). The study of the Language of Pascal as the second programming language is provided. From this point on, the algorithms on theoretical classes are recorded alternately in two languages.

Grade 11

We are studied not so much the features of languages \u200b\u200bas the algorithms. Main sections - Numerical methods (III), modeling (III), dynamic data structures (IV).