Showing posts with label arguments. Show all posts
Showing posts with label arguments. Show all posts

Saturday, May 10, 2008

Size of operator

Size of operator

The size of operator returns a number of bytes the
operand occupies in memory. The operand may be a variable,
a constant or a data type qualifier. It is a
compile time operator.

An example of size of



Output of size of operator:




The output of the above program is 2 because int occupies two byte in memory.

The size of operator is generally used to determine the
length of entities called arrays and
structures
when their size is not known to the programmer.




Function Call

Function Call

Function can be called either by value or by reference .
A function can be called by specifying its name followed
by a list of arguments enclosed in parentheses and separated by commas.

From the above example the following line is used as
a function call:


sum=add(a,b); /* function call */

Call by value: Call by value means directly pass value
within the function.

An example program of call by value:




Out put of the program


Call by reference: Call by reference means sending the
addresses of the argument to the called function.

In this method the addresses of actual arguments in the
calling function are copied into formal arguments of
the called function. (later discussed in pointer section)

The Return Statement

Information is returned from the function to the calling
portion of the program via return statement.


General form of return statement:

return;
or
return(expression);

Storage Classes

There are two different ways to characterize variables:

1. By data type
2. By storage Class

Data type refers to the type of information while storage
class refers to the life time of a variable and its scope
within the program.

A variable in c can have any one of the four storage classes:

1. Automatic Variable:

It is created when the function is called and destroy when
the function is exited. Hence the name is Automatic. By
default a variable is declared Automatic.

2. External Variable:

It is also known as Global Variable. This variables can be
accessed from any function that falls within their scope.

3. Static Variable:

A static variable may be either internal or external type ,
depending on the place of declaration.

Internal static variable extends up to the function in
which they are defined and external static variable is
declared outside of all function and is available to all
the functions in the program.

4. Register Variable:

We can tell the compiler that a variable should be kept
in one of the machine's registers, instead of keeping in the
memory (where normal variables are stored ).

Since, a register access is much faster than a memory
access and keeping the frequently accessed variables in the
register will lead to faster execution of programs.

Copyright

Copyright © 2008 C Tutorial, All rights are reserved