Monday, February 3, 2014

C programming - Expressions and commands




Lesson 8
Expressions and commands )


Hi and welcome back on learn 4 free programming!

In this lesson we are going to talk about expressions and commands. Let's start with introduction to operators, expressions and commands. After that we will take a look at the rich set of operators of C language and see how does the operators using to form expressions and commands.




          Operators of C language

C language has a wide set of operators that are used for the allocation of values​​, connect and compare objects, indirect objects, and access to many other tasks. Objects that are manipulated by the occasion are called operand . Value of the assignment operator is an operator that we have used a number of times. Symbol for it is a sign of equality ( = ).


          Expressions

Combination of operators and operands are expressions. Expression performs computation and returns the result or causes an activity.


           Commands

Command specifies an action. Commands are typically executed in the order that they are listed in program. In C language, semicolons is the final sign of the command.

The following list provides an overview of the syntax of commands that make up the functions and programs:

  • Tagged command
  • Complex command
  • Command sources
  • Expression
  • Repetition command
  • Command jump
Complex order,also called as block, is a mechanism that groups a set of commands in a single syntactic unit.


            Operators of C language (2)

As we saw earlier, some operators have only one operand. Such operators are called unary operators. Most operators in C are looking for two operands and they are called binary operators. One operator, the conditional operator, has three operands and they are called the ternary operator.

When in the expression is more than one operator, the expression may seem vague regarding the calculation sequence results.

Expression:

      + y * z

is vague because the result isn't the same if the compiler do the first addition ( x + y ) and then multiplication ( y * z ).

The C language has a built-in mechanism for determining priority of operators which is reasonable in most situations, which eliminates the need for parentheses, unless someone wants different behavior of program than standard.

Table 1 is giving overview of priority of operators in C language.


Table 1 (priority of operators)

Operators closer to the top of the priority table have higher priority than those at the bottom, and for them it says that their operands are bind tightly.
Highest category includes function calls, indexing arrays, structures, selection  member operator and pointer to the term structure.



Okay that's it for this lesson come back to learn more about C.

I will be posting more lessons about C programming, so follow me, comment if there is something you would change :) .

If something doesn't work or you need help just email me on: sashans89@gmail.com and i will help you.

See you next time, Bye.









           

No comments:

Post a Comment