FUNCTIONS and ARRAYS

on Friday, 27 September 2013
In this post we will have an overview of C functions and Arrays.As i said you before that this is not a tutorial section but just an overview.

FUNCTIONS:

Functions are the section of code which is written to perform specifically defined action. They are usually created when a single operation is performed in different parts of the main program.

The general syntax is

type name( parameter 1, parameter 2,....)
{
          Function body;
}

Type= The type of data which is going to returned by the function.
Name= Name of the function.
Parameter 1, 2,etc = Arguments of the function.

Example:

int Add(int a, int b)
{
   return ( a+ b);
}

This function is an add function. When this function is called it will return the addition result and the result is of integer type.

Function Without Returning Value:
It is not necessary that the function should return some value. Sometime we dont need any value to be returned.

Void name ( parameters)
{
       Function body


Example:

Void interrupt( )
{
   x++; 
}
This function dont return any value just it will executes the 'functional body' and returns back to its main control.

LIBRARY FUNCTIONS IN MIKROC :

MikroC compiler offers many useful functions which can be used for fast programming. To know all the verity of functions check the 'help' section of your compiler. Following is the list of libraries it offers

LCD LIBRARY
UART LIBRARY
I2C LIBRARY
CAN LIBRARY
SPI LIBRARY
CAN LIBRARY
USB LIBRARY
ETHERNET LIBRARY
PS2 LIBRARY
RS-485 LIBRARY
Many more....

But remember that using the Library functions always kills your creative thinking and programming skills. So, i suggest you to use function as least as possible. 

We only use few library functions in our programming, other than that we make our programming library free.






ARRAYS: 

Its easy for anyone to declare variables which are limited , but if we want to declare many variables then its difficult. i.e its easy to declare 5 or 10 variables independently but if we want to declare 20 or more variables we cant, so in this case we use ARRAYS. 
Arrays are the data items of similar data type.
For example we want to declare int type individual 30 variables then its an issue, but we can declare using array in the simplest way example "variable_name[30] " . 

DECLARATION: Single dimensional array can be declared as  

type name [ size ] 

Example:
double somename [ 30 ]

INITIALIZATION: 
we can initialize as 
type name[size] = { data} ;

Example:
int xyz[5]={1,2,3,4,5};
or
int xyz[]={1,2,3,4,5};

Note it is not necessary to give 'size' . If we omit size then it automatically allocates its size. 
We will full-stop the C programming section with this post. When we deal with project programming then its easy for you to understand all of these concepts. 


AUTHOR: YOUSTRON SIC




4 comments:

Anonymous said...

you are doing great bro
waiting for gsm and gps module interfacing desparately...........

emran from pakistan

YOUSTRON SIC said...

Thanq :-) I will post it as soon as possible

Aman Rustagi said...

A function in C is a sequence of statements to perform a specific task. A large C program can divide into set of functions, where each function declaration owns a particular responsibility. We can call a function any number of times in a program.

Sowpath das said...

Black education and Western education - are they different? Dr. Carter G. Woodson, father of Black History Month, in his 1933 book, The Mis-education of the Negro, said that they should be, not so much because of the differences in race as the difference of circumstances in which many African Americans are forced to live.http://www.thesisexample.info/

Post a Comment