Priority of execution of operations in expressions. Operation Priorities

Greetings, dear readers of the blog site! Last time we considered the issue of the built-in language 1C: Enterprise 8. Today we will talk about about the priorities of arithmetic operations of primitive data types, and also consider several consecutive arithmetic operations. Let's get a look!

From the school curriculum, you are familiar with the fact that highest precedence in arithmetic operations are parentheses "()".
If the expression is in parentheses, then it will be executed first of all. The unary operations "+" and "-" are next in priority, the unary operation means that the operation and one value are indicated, for example "-5". The third performs the operations of multiplication and division, and last but not least, addition and subtraction. Let's see how it works:

99+15/5*8

In this case, first 15 will be divided by 5, the resulting number will be multiplied by 6 and the third operation: 99 will be added to the resulting number. Further, the following simple expression is 10+5/2+1. It is clear that the division operation will be executed first, then the addition operation will be executed. If you use parentheses:

(90+30)/(7+5)

In this case, at the beginning we will add 90 and 30 and divide it all by 7 + 5, and in this case the expression will be equal to 10. Let's consider other operations that are possible in the 1C:Enterprise 8 program code. You may have worked in PHP, where it is possible such an operator i++; or i—;. It is an increment or decrement by one unit. The execution of such operators in 1C is impossible, but the operator is possible i++1; and j-1;. Let's take a look at them in more detail. This is a perfectly normal operator. Let's open the module of any directory in the Configurator:

Configuration -> Directories -> Nomenclature, right-click to call the item Open object module.

To avoid an error, let's declare a variable in this program code:

A=0; b=a++1;

If you check for syntax errors, then they will not be. Even if the expression is placed on different lines:

A=0; b=a+ +1;

In general, newlines do not affect the execution of statements. How would such an operator work? The 1C language compiler will first perform the unary plus operation, that is, +1 will give 1 and then to a will add one. This is the same as adding a to one. Similarly, you can write:

A=0; b=a+-1;

First, the unary minus operation is performed, it turns out -1, then the minus and plus are added together, and it turns out -1. Accordingly, this is the same as i-1. You need to be aware of these specific operations and understand how they will be performed. This will help to correctly prioritize arithmetic operations in accordance with the order we are talking about.

So, we found out that the system calmly works out an operation where there are two arithmetic operations in a row, for example ++ , +-, -+, but what happens if we write several arithmetic operations in a row? This can be verified. To do this, open 1C:Enterprise from the Configurator in debug mode, press the "F5" key. Let's set a breakpoint, the "F9" key, at the end of our expression and enter a simple expression in the scoreboard. In the Configurator, open the menu item Debug -> Tableau.

Let's write the expression 3+++5 in the scoreboard, pay attention, at the output we get an error in the expression. The platform cannot do such a transformation. The expression 3++5 works, but with three pluses, the system no longer understands what exactly they want from it. But if you put brackets 1++(+2) , then all this will be done correctly. As you can see, in order to properly organize the work of arithmetic operations, it is necessary to understand the priorities of their execution well. In the next article, we will look at .

An arithmetic expression (or simply an expression) is understood as a set of language objects connected by operation signs. As a special case, it can be just a single object.

An operation is an action that needs to be performed. The objects on which the action is performed are called operands.

When evaluating an arithmetic expression, you may need to perform several different operations. Any operation has a fixed priority level for its execution. The order of evaluation can be changed by introducing parentheses that specify the highest priority level.

If an arithmetic expression contains operands of different types, then before performing operations, automatic conversion to the type of the "highest" operand is performed. The ascending order of precedence is as follows:

char< int < long < float < double

According to the number of operands involved in a particular operation, there are three groups of operations:

Unary (one operand);

Binary (two operands);

Ternary (three operands).

According to the type of operations performed, there are arithmetic, logical, bitwise, relational, assignment and a number of others.

Arithmetic operations

The C language supports a standard set of binary arithmetic

ical operations:

Addition (+);

Subtraction (-);

Multiplication (*);

Division (/);

Taking the remainder of division of integer operands (%).

Note that there is no exponentiation operation in the C language. To perform this action, it is easy to write your own function or use a standard library function with a prototype.

double pow(double x, double y);

calculating the value of x to the power of y.

It should be remembered that the result of dividing integers is also an integer that has no fractional part: 7/4 results in one! If you need to get the remainder of an integer division, then the modulo operation, denoted by the % symbol, is used:

7%4 results in 3,

21%2 results in 1,

10%5 results in 0.

Unlike many other programming languages, in C, operator signs can be adjacent to each other:

When in doubt about the order in which operations are performed, parentheses should be used to give the highest priority to evaluating the expressions inside the brackets. First, the expression in the innermost brackets is evaluated, then in the outer brackets, and so on.

assignment operation

In C, an assignment is denoted by a single equal sign (=). The numerical value of the right side is assigned to the variable indicated on the left, and before that, the entered number is always automatically converted to the type of this variable:

The result will be a = 19.0 .

Strictly speaking, even the expression (!), right-

yes, meaningful address. So, it is quite correct to write:

C allows multiple assignments, for example:

In this case, the calculation is performed from right to left, i.e.

the value of z will be assigned to the variable w and then to the variable sum.

As a result, all three variables will receive the same value.

C also allows multi-character assignment marks. TO

they should include += , -= , *= , %= and a number of similar signs,

as well as signs of prefix and postfix increment operators ++ and

decrement --.

┌─────────────────────────────────────────────┐

│ Inside multi-character operation signs are not │

│ must be spaces!! │

└─────────────────────────────────────────────┘

Let's give examples of assignment shorthand using

signs of multi-character operations:

i += 1; means i = i+1;

i -=k; means i = i-k;

i *=k; means i = i*k;

i /=k; means i = i/k;

The prefix and postfix operations ++ and -- mean the corresponding

Increment and decrement of a variable (not necessarily integer):

K - increases the value of the variable k by one

before using it in an expression;

k++ - the same after use;

K - decreases the value of the variable k by one

before use;

k-- - the same after use.

We emphasize that the C language does not see a significant difference between an arithmetic expression and an operator. Any language expression that ends with a semicolon is a valid C statement, for example:

Of course, the result of the division is not assigned to any variable and therefore will be lost, but the following notation is quite reasonable:

which in this case is equivalent to writing

In other words, if prefix and postfix operators are used in isolation from other operators, they have the same meaning. The difference only becomes apparent when they are used in more complex expressions or statements.

With inaccurate use of the signs of these operations, a situation may arise when not exactly what we would like is calculated. Consider a typical example:

If it was meant to evaluate an expression of the form a+(++b) on the right, then the compiler will actually perceive the expression as (a++)+b. To clarify this situation, let us recall the concept of a lexeme that exists in programming languages.

A token is a unit of program text that is perceived by the compiler as a single identifiable construct that cannot be divided into smaller parts identifiable by the compiler. In the C language, lexemes are:

Official words;

Identifiers;

Operation and punctuation marks;

Constants.

Token boundaries are defined by the compiler either by the presence of another token (punctuation and operators) or by the presence of a space. If the tokens are not separated by whitespace characters, then the compiler, highlighting a separate token, combines the maximum possible number of consecutive characters into it.

Conclusion: to avoid possible ambiguity, it is recommended

use spaces or parentheses to explicitly

division of lexemes in doubtful places.

expression , and the rules for evaluating the expression. The rules are:
  • priority operations,
  • for operations of the same priority application procedure- left to right or right to left;
  • operand type conversion and implementation selection for overloaded operations;
  • the type and value of the result of performing an operation on the given values ​​of operands of a certain type.

Priority and order of operations

Most operations in C#, their precedence and order are inherited from C++. However, there are differences: for example, there is no operation " , " that allows you to evaluate a list of expressions; added checked and unchecked operations applicable to expressions.

As is usually done, we present priority table operations, each line of which contains operations of the same priority, and the lines follow in order of priority, from highest to lowest.

Table 3.1. C# operator precedence
Priority Category Operations Order
0 Primary (expr), x.y, x->y, f(x), a[x], x++, x--, new, typeof(t), checked(expr), unchecked(expr) From left to right
1 Unary +, -, !, ~, ++x, --x, (T)x, sizeof(t) From left to right
2 Multiplicative (Multiplication) *, /, % From left to right
3 Additive (Addition) +, - From left to right
4 Shift << ,>> From left to right
5 Relationships, type checking <, >, <=, >=, is, as From left to right
6 Equivalence ==, != From left to right
7 Logical AND (AND) & From left to right
8 Logical exclusive OR (XOR) ^ From left to right
9 Logical OR (OR) | From left to right
10 Conditional logical AND && From left to right
11 Conditional logical OR || From left to right
12 Conditional expression ? : From right to left
13 Assignment

Bonding with null

=, *=, /=, %=, +=, -=, <<=, >>=, &=, ^=, |= From right to left
14 lambda operator => From right to left

Overloading operations and methods

Under overloading the operation the existence of several implementations of the same operation is understood. For example, the "+" operator performs differently depending on whether its operands are integers, long integers, fixed or floating point integers, or strings of text.

You need to understand that operations are a special case of writing class methods. Class methods, like operations, can be overloaded. The class method is called overloaded if there are multiple implementations of this method. Overloaded methods have the same name, but must differ in their signature. The signature of a method is the list of types of formal arguments of the method. So two class methods with the same name but differing, for example, in the number of parameters, have a different signature and satisfy the requirements for overloaded methods.

Most of the C# language operators are overloaded - the same operator can be applied to operands of different types. Therefore, before performing the operation, a search is made for an implementation that is suitable for these types of operands. Note that operations are usually performed on operands of the same type. If the operands are of different types, then the preliminary implicit type conversion one of the operands. Both operands can be of the same type, but type conversion can still occur, because there is no corresponding overloaded operator for the given types. This situation often occurs in practice, since, for example, the operation of addition is not defined for minor subtypes of an arithmetic type. If there is no suitable implementation of the operation for these types of operands and implicit casting of operand types is impossible, then, as a rule, this error is detected at the compilation stage.

Type conversions

Each object (variable), each operand when the expression is evaluated, the expression itself is characterized by a pair that specifies the value of the expression and its type. In the process of calculations, it often becomes necessary to convert types - the need to convert a pair to a couple . The initial pair is called the transformation source, the final pair is the transformation target.

The need for such conversions arises, as already noted, in the course of expression evaluation when casting operands to a type consistent with the operation type. Type conversion is necessary in assignment statements when the type of the expression on the right side of the operator is cast to the type given by the left side of this operator. Assignment semantics also apply to method invocations in the process of replacing formal method arguments with actual parameters. This is where type conversion is needed.

Type conversions can be divided into safe and dangerous. A safe conversion is a conversion for which it is guaranteed that:

A transformation that does not satisfy at least one of these conditions is called dangerous. A sufficient condition for the existence of a safe conversion is, for example, the condition that a type is a subtype of type . Indeed, in this case, any source value is also a valid target value. Thus, the conversion from type int to type double is safe. The reverse transformation would naturally be dangerous.

Some type conversions are done automatically. Such conversions are called implicit conversions, and they often occur when evaluating expressions. Obviously, only safe conversions can be implicit. Any dangerous conversion must be explicitly specified by the programmer, who takes full responsibility for performing the dangerous conversion.

There are different ways to perform explicit conversions - casting operation (casting to a type), methods of the special class Convert , special methods ToString , Parse . All of these methods will be discussed in this lecture.

Let us explain how implicit conversions are performed when an expression is evaluated. Let , when calculating some expression , it is necessary to perform addition , where it has type double , and - int . Among the numerous implementations of addition are operations that perform addition of operands of type int and addition of operands of type double, so choosing either of these addition implementations will require a type conversion of one of the operands. Since the type conversion from int to double is safe and the other way is dangerous, a safe conversion is chosen and performed automatically, the second operand is implicitly converted to type double, the operands of this type are added, and the result of the addition will be of type double .

Organizing the ConsoleExpressions Programming Project

As usual, all code examples that appear in the text are part of the software project. I will describe the structure of the console project used in this lecture, called ConsoleExpressions. In addition to the default Program class, two classes have been added to the project, named TestingExpressions and Scales . Each of the methods of the TestingExpressions class represents a test that allows you to analyze the features of the operations used in constructing expressions, so this class is a collection of tests. The Scale class is informative, demonstrating how to work with the scales that will be discussed in this lecture. To be able to call the methods of these classes, objects of these classes are declared and created in the Main procedure of the Program class. These objects are then used as the target of calling the appropriate methods. The general scheme of the Main procedure and calling methods of the class is as follows:

static void Main(string args) ( string answer = "Yes"; do ( try ( TestingExpressions test = new TestingExpressions(); test.Casting(); //Call other methods... ) catch (Exception e) ( Console.WriteLine( "Can't continue normally!"); Console.WriteLine(e.Message); ) Console.WriteLine("Shall we continue? (Yes/No)"); answer = Console.ReadLine(); ) while (answer == " Yes" || answer == "yes" || answer == "yes"); )

Whenever a code example needs to be given in the text of the lecture, either the full text of the method being called, for example, the Casting method, or a separate fragment of the method will be given.

Lecture 4 Department of Applied Mathematics M-703, tel. 362-79-62 Ph.D., professor Glagolev Viktor Borisovich, room. Zh-405b, tel. 362-73-28 http://glagvik.narod2.ru/index.htm Arithmetic operations Priority of arithmetic operations Mathematical functions Arrays Logical operations Priority of operations


Operations and Functions VB has a large set of built-in functions. They can be divided into several categories: Finance functions Math functions String processing functions Type conversion functions Other functions


Acquainted with detailed description functions can be found in the VB help system. In the following, we will only look at VB math functions. The table on the next slide gives a complete list of operations that can be applied to numerical data.


Arithmetic operations

relation operations


Operator precedence If multiple operators are used in an expression, the operators with the highest priority are executed first. If the priority of operations is the same, then they are executed from left to right. a + b/c + d (a + b)/(c + d) Examples Expression Code


Math functions

Angles are expressed in radians. The project needs to import the System.Math namespace by adding the line Imports System.Math to the beginning of the source code (before the declaration of the first module or class). Otherwise, it will be necessary to add the class name before the name of each function, for example: Math.Sin(x)


Import into the System.Math namespace project


The Int and Fix functions return a value equal to the integer part of a number whose type is the same as the type of the argument. Syntax: Int(number) and Fix(number) The required argument number is any valid numeric expression.


The difference between the Int and Fix functions is that for a negative argument value, the Int function returns the nearest negative integer less than or equal to the specified value, while Fix returns the nearest negative integer greater than or equal to the specified value. For example, the Int function converts -8.4 to -9, and the Fix function converts -8.4 to -8.


The Rnd function returns a Single value containing a random number less than 1 and greater than or equal to 0. Before the first call to the Rnd function, you must use the Randomize() statement with no argument to initialize the random number generator.


Example. Game "Guess the number" Condition of the game The computer guesses some random integer k from the range 0 - 100. You should guess the guessed number, making as few attempts as possible. After each attempt, the computer reports whether the hidden number is greater or less than the proposed number.


data table


Algorithm block diagram Generating a random number k from 0 to 100 Input k1 a



Interface


Property Values


Program code

Arrays An array is a group of variables containing data elements of the same type and with the same name. A separate memory cell is allocated for each element of the array. All elements of an array are of the same type. Links to individual array elements are possible. Each individual array element is defined by the array name and index values.


For example, references a(7) or a1(2, 9) mean that: a is the name of a one-dimensional array (vector) with one index, the array element has an index value of 7. a1 is the name of a two-dimensional array (matrix). This is indicated by the use of two indexes to determine the element of the array.


The first index of a two-dimensional array is interpreted as the row number in which the array element is located, and the second index is treated as the column number. The index can be an integer type expression with a non-negative value. The lower bound of an index is always 0. The upper bound of each array index is specified when it is declared.


Array name Index (position number) of the array element km Example of an array with the name km of the Integer type of the kilometers counter readings on the car's speedometer at the beginning of each month throughout the year:


Like simple variables, arrays are declared using the Dim, Static, Private, or Public statements. Array declaration examples: Dim x() As Single Dim y(,) As Single


A one-dimensional array named x and a two-dimensional array y are declared. This is indicated by parentheses in the declaration after the name of each array. When declaring a two-dimensional array, there must be a comma between the brackets. The declaration of the upper bounds of the indices in these examples is deferred until later (such arrays are called dynamic arrays). A one-dimensional array is called a vector. A two-dimensional array is called a matrix.


To declare the upper bound of the index and allocate arrays in memory, you should place the instruction: Redim x(10), y(4,5) Here, the values ​​of the upper bounds of each array index are specified.


The x array index can take a value between 0 and 10. The x array has 11 elements. The first index of the y array can be between 0 and 4. The second index of the y array can be between 0 and 5. The y array has 30 elements (number of rows times number of columns).


When declaring an array, you can initialize it: Dim z() As Single = (1.3, -2.7, _ 14.6, -5) In this example, a one-dimensional array z is declared, which has 4 elements, the values ​​of which are given by the initialization list. An array whose declaration did not specify the upper bounds of the indices (dynamic array) can be repeatedly redeclared using the ReDim instruction.


Among the instructions inside the procedure, you can write: ReDim y(5, 10) Further, this array can be redeclared: ReDim y(5, 20)


The ReDim statement can only change the upper bounds of indexes. The dimension of an array (the number of indices) can be set once. It cannot be changed. The ReDim statement can be used to modify a dynamic array as many times as needed. However, each time it is used, the data contained in the array is lost.


The ReDim Preserve statement can increase the size of an array while preserving its contents. The following example shows how you can increase the size of the array a4 by 10 elements without destroying the current values ​​of the array elements. Let an array be declared: Dim a4 () As Integer Then the size of this array is set in the program: ReDim a4 (n)



If the upper bounds of the indices are specified when declaring an array, then such an array is called a fixed array. Example Dim s(10) As Single Dim b(4, 5) As Integer ReDim is not applicable to fixed arrays.


It is possible to assign the contents of one array to another in the same way as it is done for simple variables. But these arrays must have the same dimension and the same number of elements.


If there is a dynamic array on the left side of the assignment operator, then the number of elements does not have to match. The number of array elements on the left side of the assignment statement will change if necessary.


Example. Dim a() As Integer = (1, 2, 3, 4), _ b(), i As Integer b = a For i = 0 To 3 MsgBox(b(i)) Next output: 1, 2, 3, 4.


Example 1 Calculate the arithmetic mean of k given numbers.


Applied data Initial data: k – integer type variable, number of specified values; a() – array of Single type, values ​​of given values. Results: s is a variable of type Single, the value of the arithmetic mean.


Intermediate: Sum – variable of type Single, the value of the sum of the first k elements of the array a; i – integer type variable, index value of array element a.


Block diagram of the algorithm (1) (2) 1


(3) (4) (5) (6) (7) (8) 1 2 No



Let's look at this block diagram in terms of the basic structures that it includes. Blocks 1 - 2 make up a sequential structure (following), which we will call Structure 1. Blocks 3 - 8 refer to the cycle. We will call this structure Structure 2. Blocks 9 and 10 are again a sequential structure, which we will call Structure 3.


Structure 1, Structure 2, and Structure 3, taken together, are also a sequence structure. In the flowchart of any structured algorithm, one can always clearly see the basic structures from which the algorithm is built.


Project interface The text field is designed to display the results of calculations. Pressing the button will start the calculations.


Project interface


Project Code When you create a project, the system automatically generates the following stub code associated with Form1, which is a declaration of the Form1 class. All code associated with the form must be inside this template.


The execution of the project should start with a click on the BtnStart button. Therefore, the project code must include a subroutine BtnStart_Click, the execution of which is triggered by the Click event that occurred with the BtnStart button (clicking on this button).


The next step in creating the project code should be to include the BtnStart_Click subroutine in the project code, which is created by the system if, for example, you double-click on the BtnStart button.


Below is the code that will result after creating the BtnStart_Click subroutine blank.

After the project is launched for execution, the program code will start executing only after pressing the BtnStart buttons. In this case, a Click event occurs for this button, which causes the BtnStart_Click event procedure to be executed. Solution Results

Lines 1 through 5 of the body of this procedure declare data. Line 6 clears the text field. To do this, use the Clear method. If this is not done, then during multiple launches of the project, the information displayed in the text field at the next launch will be added to the information displayed in it during previous launches.


Line 7 provides input for the variable k. It is recommended that you always check the correctness of data entry. It is for this purpose that in line 8 the value of the variable k is displayed in the text field. Line 9 allocates the array a in memory.


In lines 10 to 12, the values ​​of the elements of the array a are entered. The value of the element a(0) is not entered in this case. We will ignore the presence of this element. It will not apply anywhere. In lines 13 to 16, the values ​​of the entered elements of the array a are displayed for control in the text field.


Lines 17 to 20 evaluate the value of the variable s. And finally, line 21 provides the output of the variable s in the text field.


Note that the program does not contain the instruction i = 1, nor the instruction i = i + 1, even though these instructions are in the flowchart. There is also no verification of the condition i<= k. Выполнение всех этих действий обеспечивает инструкция цикла For … Next.


Note that the program also does not contain the instruction sum = 0. The value 0 was given to the variable sum as a result of its declaration. You can remove the Dim i As Integer statement. The For...Next loop statement is a block. The variable i inside the block will automatically receive the Integer type (according to the type of the initial and final values ​​of the parameter), but will only act inside the block.


Logical Operations VB.NET defines logical operations: And (logical multiplication), Or (logical addition), Not (logical negation), and Xor (logical exclusive addition). The Not operator has the following syntax: Not Operand


An operand that has a boolean type is a relation, a variable or function of a boolean type, or the result of a boolean operation. The result of a logical negation has the opposite value of its operand, as shown in the table below.


Operation Not Not Operand


The And operation has two operands: Operand 1 And Operand 2 The result of the And operation is defined by the table:


The And operator is True only when both operands are True. Example Inequality a ? x? b should be written: a<= x And x <= b Неправильно написать: a <= x <= b


The Or operation also has two operands: Operand 1 Or Operand 2 The result of the Or operation is given in the table:


The Or operator evaluates to True if at least one operand (and even both) evaluates to True. Example: The condition "x does not belong to the segment" should be written: x< a Or x >b or Not(a<= x And x <= b)


Xor (logical exclusive addition) The result of the Xor operation is given in the table: The Xor operation is True if one of the operands (but not both) is True.


VB.NET also defines logical operations: AndAlso and OrElse. The AndAlso operation is very similar to the And operation. It also performs a logical multiplication on the two boolean operands (Boolean).


The main difference between AndAlso and And is that AndAlso allows for reduced, incomplete evaluation of operands. If the first operand in AndAlso evaluates to False, the second operand is not evaluated and the AndAlso operation returns False.


Similarly, the OrElse operation is very similar to the Or operation. It performs a shorthand logical addition of two logical operands. If the first operand in the OrElse expression is True, the second operand is not evaluated and True is returned for the OrElse operation.

The order in which operations are performed when calculating the value of an expression is determined by location of operation signs, parentheses and operations priority . The operations with the highest priority are executed first. If an expression contains several operations of the same priority at the same level, then they are processed in accordance with the order of execution - from right to left or from left to right. If you need to change the order of operations in an expression, then you should use parentheses, for example (x + y) * z .

Priority operations comma lower than all other transactions.

The following table lists the C++ language operations in descending order of precedence. Operations with different priorities are separated by a bar.

Operation Priority Table

Operations signs

Operation names

Order of execution

priority boost

postfix increment

postfix decrement

from left to right

sizeof

( a type ) expression and

type (expression)

operand size in bytes

prefix increment

prefix decrement

bitwise H E

logical NOT

unary minus, plus

type conversion

on right left

multiplication

remainder of integer division

from left to right

addition

subtraction

from left to right

shift left

right shift

from left to right

less or equal

more or equal

from left to right

from left to right

bitwise AND

from left to right

bitwise exclusive OR

from left to right

bitwise OR

from left to right

logical AND

from left to right

logical OR

from left to right

? :

conditional

on right left

*= , /= , %=

+= , - =

<<= , >>=

&= , |= , ^=

assignment (simple and

composite)

on right left

operation comma

from left to right

Type casting (conversion)

Programming language C++, being a typed language, nevertheless allows you to handle expressions that operate on various data types quite freely. In this case, the operands of the expression are cast to some common type.

Only conversions that convert smaller-ranged operands to larger-ranged operands are automatically performed, since this happens without any loss of information. For example, if in the expression ival + fval variable ival type int , and the variable fval– type float , then when executing operations(+ ) variable value ival will be cast to type float .

Expressions in which information might be lost, such as when long integers are assigned to shorter or real integers, may cause warnings (Warnings), but they are valid (see the assignment operator).

Any expression can be explicitly converted to its type using a unary operation called cast (transformation) type . The operation can be written in two formats:

(a type) expression

a type(expression)

operand operationstype casting is the expression to be converted. Priority cast operations the same as for other unary operations. For instance: (longdouble) 5; (int) f ; (double) a/2 .

If the expression in question has a fairly complex form, it is advisable to take it in parentheses to make sure that the type will be changed for the result of the entire expression, and not for part of it. For instance,

(int) x+b*c

(int) (x + b * c )

In the first case, the transformation refers to the variable x , in the second - to the whole expression x+b*c.

Loading...Loading...