08.1 (conspect) C programming language at a glance

Foreword: If we are talking about C in general, we will try to fill in the gaps in the topics we have already covered.

At the seminars there were questions that were related to C and C++ languages: in the first place, of course, about the notation += and -= and so on - any operation in C, whether bit or arithmetic, supports this syntax. In this case, the left part is the assignment place - the left place of the expression.

- differ in the fact that if you do not include optimizations, the broadcast in 1 version is more efficient than in 2 lines. With optimization turned off C comes "silly" it turns everything it sees before it into an assembler code.

Although in the trailer it will be about the same - both designs are about the same. Let's try to look at them after compiling. But in some architectures with complex system or situation when variable is register - there can be a difference between translations of these two things.

If there is an add-on operation, this broadcast is more efficient. Symmantics +/- uveleniche a. But more importantly, in terms of efficiency, the reduction of the increase by 1.

Second question about..:

- exists hardware. Let's call in one assembly instruction. There were many such architectures in the C era, for example, the architecture on which Thomsan and Wichie were working in both variants.

Check

Let a = 5, b = 6.

Output:

A solicitation operation is an operation with a return value.

Another feature is:

- it works in python, but it doesn't work in C => it records in C:

- now that's going to go to C. The arithmetic operation which is calculated starting from the 'right' as an erection to the extent and in fact we can use such That's the same trick used to base the semicolon operation In C, we rarely use it. When we write something like this:

- it has a return value. The first element of the semicolon

- so, we'll replace both A and C. And A and C are just two operators. Also, we could rewrite is like:

- just calculation difference.

this is rarely necessary. It is not recommended to use when we are not sure

//а = 1,2,3,4 - diagnosis will come out.

Language C is a very kind language. In this case a = 1. Perfect language for simple commands. Nobody's gonna tell us anything. Wall - enable all warning messages - we will be told that we have comma expressions there that they use only the very first element, all other effects have no effect.

Variable C was nowhere involved in the operation. The brain is built into the C language that says you set the variable but didn't use it.

- the diagnostician doesn't come out, it's a valid design.

In terms of types:

Void is not a type at all in a way. Because there are no output type variables. It's used in two cases.

Modifier:

Modifier - a variable of two species - not overlapping:

We see the assemble code: vim static.c

Look. Here's a statistical i and dynamic j that starts on the stack when we call the fstsat function and kills when we get out of there if we hadn't initialized the garbage would be lying there. The statistical count will be initialised once during the compilation of the program, placed in memory in a special place of RAM, and it will be more and more. What will be the program output? 5 times it will print these lines... :

The statistics is initiated by the variable once at compile-time. While that local variable may still be counted in different places. There are no local labels in the assembler, so the compiler invented the name of сount.1954.

Functions:

Remember that the function can return some banners, and we can score! Scanf - return scanned fields If you want 3 fields, we entered 2 - scanf will return 2.

Initially, there was no 'void' in C - instead of 'void' there was 'int'. Functions return 'int' - we can use it, but we can not use it. The theory says: all the passes of all the parameters are passed only by value (in c++, pass by reference) in C only by value. The fact that the weight of the value you pass to the function provokes one thing: if you want your function to change a variable, you have to pass a pointer to it, not the value of this variable - for the function to write something where we want it to go - you have to pass its address!!!

So we put a &. At the beginning, because you have to pass the address.

Let's say that when we enter an array, we pass the array name to Potmo that this is the pointer in the arrays. Because of this, a pointer to a pointer appears in C - int **p - let's imagine that we wrote void findcell(int **p, int *arr, int len, int value) must find value and return this address to memory, but the void function - and it must write this address to memory into a variable. The value being rotated is not the result of the function's work. The returned errors (the error number) and if the function must change something - we must pass the pointer to the place it must change).

We want the function to find the value element if it does not return a NULL addressing error. Technically, NULL may not be 0.

As a result, p indicates a cell in array A. Data type inheritance reference int - no other way. We do not transfer by reference only by value. There are also three stars.

Control flow

The simplest things in C that might not be worth talking about: But since C and C++ are exactly different languages, we'll talk:

Many people think that a cycle for a cycle with a counter is not true.

Output:

C programs:

Output:

We have a character in the input stream that scanf does not recognize as long as I ask for two integers on the assembler garbage scanf just returns here 0 fields entered. And we have this unrecognized symbol in the input stream.

If we see an infinity when the program is processing an input, that's it:

switch() - unconventional conditional operator - breaks the principle of structural programming where each conditional operator should have one branch Inside the operator, the expression is an integer - it is calculated. The result of the expression will be a number, this expression calculates the further go on the label of the case which is according to the number - perform operators - no operator brackets here, as a label. That's why we should put 'break' after the operator sequence. If we don't, we get to the next one. And if no case is okay, we win, but we can put a break. 1. Line break is a separate character. 2. Until we click on line feed, the input is accumulated in the input buffer. Input a line, you can edit it. 3. You enter the characters into it as a whole number. 4. If the end of the file occurs when typing from the file or 2 ways to press specially / combination of keys ctrl + d When we work with the terminal, the managed bytes can be of different types - in particular, when we output. Control symbols - the Linux itself has processed it for us or crtl+d - a symbol with code 4, does not return 4, closes -1.

Eof is '-1' as a rule. There's a duuf link - it's for those who have understood the topic!

HSE/ProgrammingOS/08_SurveyOfC/Conspect_en (последним исправлял пользователь NataliaKrauze 2020-02-21 16:05:57)