Showing posts with label variables. Show all posts
Showing posts with label variables. Show all posts

Friday, May 16, 2008

Scope of variables: LOcal and Global

Scope of variables: LOcal & Global

Scope of variable means where the variable stands in the program. All variables may not necessary be available to all statements in a program.

Variables can have two types of scope:

a) Local:

When a variable is declared inside the function then such a variable is known as local variable.

A local variable can only be accessed by the function in which it is declared. It cannot be accessed by other function.

b) Global:

A variable which is declared outside all functions is known as global variable.

A variable with a global scope is accessible to all the statements in the program. A global variable can be accessed by all the functions.

Wednesday, May 14, 2008

Conditional & ternary operators

Conditional & ternary operators

The conditional operator? and: are sometimes called ternary operators.

A ternary operator is one which contains three operands.

The general form of ternary operator is:

exp 1 ? exp 2 : exp 3

The operator works as, if exp 1 is evaluated first. If the result is true then exp 2 is executed, otherwise exp 3 is executed.

Saturday, May 10, 2008

Expression

Expression

Evaluation of expression

An expression is a combination of variables, constants
and operators arranged according to the syntax of the language.

C can handle any complex expression with ease.

It is little bit different from algebraic expression.

Algebraic Expressions C Expressions
axb-cxd a*b-c*d
(m+n)(a+b) (m+n)*(a+b)


Evaluation of expression:

We can evaluate an expression by using assignment statement. As

Variable = Expression.

e.g. :

Temp = ((f * cos(x)/sin (y))+(g * sin(x)/cos(y)))

All relevant variables must be assigned values
before the evaluation of the expression.

Type conversion in expression:

To effectively develop C programs, it would be necessary
for you to understand the rules that are used for the
implicit conversion of operands.

If an expression contains an operation between an int
and a float, the int would be automatically promoted to
a float before carrying out of operation.

Copyright

Copyright © 2008 C Tutorial, All rights are reserved