C Keywords C

There are certain reserved words in ‘C’, which are called keywords. The compiler already knows meaning of keywords. Following are few standard keywords

auto break case extern float far
sizeof static struct

They are all written with small case letters. Keywords cannot be used as variable name as it will alter their meaning.

Operands, operators and Expression
• Arithmetic operators
• Unary operators
• Assignment operators.

Operands and operators are both together used to form expressions. Data items that operators act upon are called operands. Operands can be constants or variables. When all the operands in an expression are constant it is called a constant expression. Most operators require two operands to operate upon. They are called binary operators.
Some operators require single operands; they are called unary operators. We will see how arithmetic operators; unary operators and assignment operators are used.

Logical (Result = operand1 operator operand2) * / Expression */

Arithmetic Operators
There are five arithmetic operators in ‘C’

Arithmetic Operators
The operands must be numeric values i. e. they can be integer quantities, floating point or character quantities (each character represents an integer value). When both operands of division operator (/) are integers, result is an integer. It is called integer division. Integer division result in truncation towards zero. If both operands are floating point or if one is floating point and one is integer, result is floating point.

There is no operator for exponentiation in ‘C’.
Arithmetic instruction can be formed as

/* variable declaration */ int ad; float k = 4.0, alpha = 10.0, beta = 8.0, /* variableinitialized during declaration */ float delta; delta = alpha *beta / k + 3.2 * 2 / 5 ; /* arithmetic instruction */

The expression on the right of ‘=’’ is evaluated and assigned to variable on the left hand side of ‘=’. As it is seen initialization can be done during declaration.

Unary Operators

  • Minus operator.
  • Increment and decrement operator.
  • Sizeof operator.
  • Unary operators require a single operand.

Minus Operator
Minus sign precedes a numerical constant, a variable or an expression. It is used for negation. It is different from arithmetic subtraction operator.
E. g. -1 -3.0

Increment and Decrement Operator
These are used for incrementing and decrementing variables. Increment operator ‘++’ adds 1 to its operand, while decrement operator ‘_’ subtracts 1 from its operand. The operator may be postfixed or prefixed. Postfixing and prefixing makes a difference when the operators are used in expression.

E. g.

j++ ; ++j ;

Both are same when used as simple statements.

If we have

j = 3 ; X = j+ + ;

Here j is first assigned to x and then increment by 1. Hence X = 3, J = 4;

X = + + j ;

Here j is first incremented and then assigned to x. Hence x = 4, j = 4;

Sizeof Operator
It returns the size of its operand in bytes.

int i , j ; j = sizeof (i) ;

will give j = 2. (Since integer occupies 2 bytes and i is an integer).

Assignment Operator
When we write an expression

x = a + b ;

Here ‘=’ is the assignment operator. In this case expression on the right of ‘=’ is evaluated and value is assigned to the variable on the left.

There is one more type of assignment operator. If we have an expression where variable on the left is repeated immediately on the right, it can be written as:

i = i + 2 ; i + = 2 ;

The operator ‘+’ is called the assignment operator. Most binary operators have corresponding assignment operators. General form of assignment expression being

expr1 op = expr2 ;


expr1 = (expr1) op (expr2) ;

Where expr1 and expr2 are expressions and op can be one of the operators.

+ - * / % << >> & ^ |
There are more five operators known as bitwise operators which would be taken up in miscellaneous
This type of assignment operators make long expression easy to work with.

E. g.

yyval [yypv [p3 + p4] + yypv [p1 + p2] ] + = 2; is easier than yyval [yypv [p3 + p4] + yypv [p1 + p2] ] = yyval [yypv [p3 + p4] + yypv [p1 + p2] ] + 2 ;

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

C Topics