Wednesday, 26 June 2013

CRIMINAL CASE free extra 5 energy

Need EXTRA Energy Points?

Try to beat your friends' best score with these 5 FREE Energy Points!

http://2sm.pl/19tjwft   << Get 5 Energy Points



Earn free mobile recharge

Earn money by just receiveing adds message in your cell phones
register your mobile number in mginger and confirm your email to earn mobile recharge
click here to register mginger  and start earning..

Thursday, 20 June 2013

Tamil Graphics Kavithaikal


























STORAGE CLASS in C language

STORAGE CLASS
There are 2 different ways to characterize variables:
By datatype
By storage class
DATATYPES
It refers to the type of information represented by a variable eg., integer number, floating point number, character etc.
STORAGE CLASS
A variable’s storage class tells us:
 (a) Where the variable would be stored.
(b) What will be the initial value of the variable, if initial value is not specifically assigned.(i.e. the default initial value).
(c) What is the scope of the variable; i.e. in which functions the value of the variable would be available.
(d) What is the life of the variable; i.e. how long would the variable exist.
TYPES:
(a) Automatic storage class (keyword is auto)
(b) Register storage class (keyword is register)
c) Static storage class (keyword is static)
(d) External storage class (keyword is external)
NOTE Keyword that specifies a particular storage class must be placed at the beginning of the variable declaration.
AUTOMATIC STORAGE CLASS
Storage − Memory.
Default initial value − an unpredictable value, which is called a garbage value.
Scope − Local to the block in which the variable is defined.
Life − Till the control remains within the block in which the variable is defined.
Keyword auto is used to declare the automatic variable.
Automatic variables are always declared within the function and are local to the function in which they are declared. Their scope is confined to that function.
Automatic variables defined in different functions will therefore be independent of one another, even though they may have the same name.
Memory is allocated automatically upon entry to a block and freed automatically upon exit from the block.
The values of automatic variable will be reassigned each time the function is reentered.
An automatic variable does not retain its value once control is transferred out of its defining function.
Therefore, any value assigned to an automatic variable within the function will lost once the function is exited.
main( )
{
 auto int i, j ;
 printf ( "\n%d %d", i, j ) ;
}             The output of the above program could be... 1211 221
Where, 1211 and 221 are garbage values of i and j. When you run this program you may get different values, since garbage values are unpredictable.
Scope and life of an automatic variable is illustrated in the following program.
main( )
{
 auto int i = 1 ;
 {
  auto int i = 2 ;
  {
  auto int i = 3 ;
  printf ( "\n%d ", i ) ;
  }
  printf ( "%d ", i ) ;
 }
 printf ( "%d", i ) ;
}
 The output of the above program would be: 3 2 1
Note that the Compiler treats the three i’s as totally different variables, since they are defined in different blocks.
Once the control comes out of the innermost block the variable i with value 3 is lost, and hence the i in the second printf( ) refers to i with value 2.
Similarly, when the control comes out of the next innermost block, the third printf( ) refers to the i with value 1.
EXTERNAL STORAGE CLASS
The features of External variable
Storage − Memory.
Default initial value − Zero.
Scope − Global.
Life − As long as the program’s execution doesn’t come to an end.
External variables are declared outside all functions
The scope of the external variables extends from the point of its definition through the remainder of the program.
The external variable can be assigned a value within one function, and this value can be used within another functions

NOTE:
An external variable declaration does not reserve storage space. Hence, a definition is essential to create external variable.
External Variable Definition:
It is also looks like a ordinary variable declaration.
It must appear outside of, and usually before the functions that access the external variables.
When an external variable is defined, memory is allocated for it.
The keyword ‘extern’ is not required in an external variable definition.
Syntax:
Datatype variable=value;
An external variable must be defined only once.
External Variable Declaration:
Syntax:
extern datatype var1,var2…var-n;
§ An external variable declaration cannot include the assignment of initial values.
§ The memory is allocated for the external variable when the program starts, and the memory is only released when the program ends.
Example:
int i ;
main( )
{
 printf ( "\ni = %d", i ) ;
 increment( ) ;
 increment( ) ;
 decrement( ) ;
 decrement( ) ;
}
increment( )
{
 i = i + 1 ;
printf ( "\n on incrementing i = %d", i
}
decrement( )
{
 i = i - 1 ;
 printf ( "\n on decrementing i = %d", i
}
The output would be:
i = 0
on incrementing i = 1
on incrementing i = 2
on decrementing i = 1
on decrementing i = 0



STATIC STORAGE CLASS
The features of static storage class:
Storage − Memory.
Default initial value − Zero.
Scope − Local to the block in which the variable is defined.
Life − Value of the variable persists between different function calls.
Example for auto variable:
 main( )
 {
  increment( ) ;
  increment( ) ;
  increment( ) ;
 }
 increment( )
 {
  auto int i = 1 ;
  printf ( "%d\n", i ) ;
  i = i + 1 ;
 }
The output of the above programs would be:
1
1
1

main( )
{
  increment( ) ;
  increment( ) ;
  increment( ) ;
}
 increment( )
{
  static int i = 1 ;
  printf ( "%d\n", i ) ;
  i = i + 1 ;
}
The output of the above programs would be:
1
2
3

Like auto variables, static variables are also local to the block in which they are declared. The difference between them is that static variables don’t disappear when the function is no longer active. Their values persist.
If the control comes back to the same function again the static variables have the same values they had last time around.

REGISTER STORAGE CLASS
Features
Storage - CPU registers.
Default initial value - Garbage value.
Scope - Local to the block in which the variable is defined.
Life - Till the control remains within the block in which the variable is defined.
A value stored in a CPU register can always be accessed faster than the one that is stored in memory.
main( )
{
 register int i ;

 for ( i = 1 ; i <= 10 ; i++ )
  printf ( "\n%d", i ) ;
}


functions i C language

 FUNCTIONS
A program can be used for solving a simple problem or a large and complex problem. Programs solving simple problems are easier to understand and identify mistakes, if any, in them. Complex programs are usually larger. If a program is large, it is difficult to understand the steps involved in it. Hence, it is subdivided into a number of smaller programs called subprograms or modules. Each subprogram specifies one or more actions to be performed for the larger program. Such programs are called as functions/subroutines.
DEFINITION:
A function contains sequence of instructions to perform any task, which is used (or invoked) by the main program or other subprograms. A subprogram receives values called arguments from a calling program, performs calculations and returns the results to the calling program.
Advantages
1. The length of the source program can be reduced by using functions at appropriate places.
2. A function can be used to avoid rewriting the same sequence of code at two or more locations in a program.
3. If the program is large, then it is divided into subprograms, each subprogram can be written by as a function.
4. Programs with using functions are compact & easy to understand.
TYPES OF FUNCTIONS
Based on the nature of creation, functions are classified as
1) Built-in functions
            Built-in functions are predetermined and supplied along with the compiler and these can be used in any C program. These are also known as library functions.
2) User-defined functions
The functions defined by the users are called as user-defined functions.
  To make use of the user defined functions, the programmer must be able to
Define a function
Declare the prototype of a function and
Invoke/call the function
 FUNCTION DEFINITION
  A function definition describes what a function does, that is a function definition specifies the operation of the function. The general format for defining a function is
 Return-type function name (parameter list)
  {
  Declaration(s);
  Statement(s);
               Return (expression);
  }
Example :
mul (int a,int b)
{
int y;
y=a+b;
Return y;
}

When the value of y which is the addition of the values of a and b. the last two statements
ie, y=a+b; and return y; can be combined as return(a+b) or return a+b;

FUNCTION DECLARATION
 A function declaration is made by declaring the return type of the function, name of the function and the data types of the arguments of the function.  A function declaration is same as the declaration of the variable. The function declaration is always terminated by the semicolon.
Before function calling, we should declare that function. Function call may come before the main() or before clrscr().
The general form of the declaration is:-
return_type function_name(parameter list);
For example function declaration can be
            int factorial(int n1,float j1);
 Another method can be
      int factorial(int , float);
 The variables in the function declaration can be optional but data types are necessary.
Formal parameters
These are the names used inside a function to refer to its arguments.
Actual arguments
These are the values used as arguments when the function is actually called. In other
words, the values that the formal parameters will have on entry to the function.
Rules:
The sequence of the arguments in the function call should be same as the sequence of the parameters in the parameter list of the function declaration. The data types of the arguments should correspond with the data types of the parameters. When a function call is made the value of the actual arguments will replace the formal parameters of the function.

FUNCTION PROTOTYPES

A function prototype is a function declaration or definition which includes information about the number and types of the arguments that the function takes.

THE RETURN STATEMENT AND RETURN VALUES
A return statement is used to exit from the function where it is. It returns the execution of the program to the point where the function call was made. It returns a value to the calling function. The general form of the return statement is:-
             return expression;
 The expression evaluates to a value which has type same as the return type specified in the function declaration.
TYPES OF FUNCTIONS
1. Functions with no arguments and no return values.
2. Functions with arguments and no return values.
3. Functions with arguments and return values.
4. Functions with no arguments and return values.

1. FUNCTIONS WITH NO ARGUMENTS AND NO RETURN VALUE.
A C function without any arguments means you cannot pass data (values like int, char etc) to the called function. Similarly, function with no return type does not pass back data to the calling function. It is one of the simplest types of function in C.
Example:
1. #include<stdio.h>
2. #include<conio.h>
3. void printline()
4. {
5. int i;
6. printf("\n");
7. for(i=0;i<30;i++)
8. {
9. printf("-");
10. }
11. printf("\n");
12. }
13. void main()
14. {
15. clrscr();
16. printf("Welcome to function in C");
17. printline();
18. printf("Function easy to learn.");
19. printline();
20. getch();
21. }
Source Code Explanation:
Line 3-12: This block is a user defined function (UDF) whose task is to print a horizontal line. In line no. 7 I have declared a “for loop” which loops 30 time and prints “-” symbol continuously.
Line 13-21: These line are “main()”  function. Line no. 16 and 18 simply prints two different messages. And line no. 17 and 19 calls our user defined function “printline()”.
FUNCTIONS WITH ARGUMENTS AND NO RETURN VALUE.
This type of function can accept data from calling function. In other words, you send data to the called function from calling function but you cannot send result data back to the calling function. Rather, it displays the result on the terminal.
Example:
1. #include<stdio.h>
2. #include<conio.h>
3. void add(int x, int y)
4. {
5. int result;
6. result = x+y;
7. printf("Sum of %d and %d is %d.\n\n",x,y,result);
8. }
9. void main()
10. {
11. clrscr();
12. add(30,15);
13. add(63,49);
14. add(952,321);
15. getch();
16. }

.
Source Code Explanation:
This program simply sends two integer arguments to the UDF “add()” which, further, calculates its sum and stores in another variable and then prints that value.
Line 3-8: This block is “add()” which accepts two integer type arguments. This UDF also has a integer variable “result” which stores the sum of values passed by calling function (in this example “main()”). And line no. 7 simply prints the result along with argument variable values.
Line 9-16: This block is a “main()” function. In 12, 13, 14 lines we have called same function “add()” three times but with different values and each function call gives different output.
FUNCTIONS WITH ARGUMENTS AND RETURN VALUE.
This type of function can send arguments (data) from the calling function to the called function and wait for the result to be returned back from the called function back to the calling function. The data returned by the function can be used later in our program for further calculations.
1. #include<stdio.h>
2. #include<conio.h>
3. int add(int x, int y)
4. {
5. int result;
6. result = x+y;
7. return(result);
8. }
9. void main()
10. {
11. int z;
12. clrscr();
13. z = add(952,321);
14. printf("Result %d.\n\n",add(30,55));
15. printf("Result %d.\n\n",z);
16. getch();
17. }
Source Code Explanation:
This program sends two integer values (x and y) to the UDF “add()”, “add()” function adds these two values and sends back the result to the calling function (in this program to “main()” function). Later result is printed on the terminal.
Line No. 3-8: Look line no. 3 carefully, it starts with int. This int is the return type of the function, means it can only return integer type data to the calling function. If you want any function to return character values then you must change this to char type. On line no. 7 you can see return statement, return is a keyword and in bracket we can give values which we want to return.
Line No. 9-17: In this block, we have declared an integer “z” which we used in line no. 13. Why we are using integer variable “z” here? Bec UDF “add()” returns an integer value on calling. To store that value we have declared an integer value. We have passed 952, 321 to the “add()” function, which finally return 1273 as result. This value will be stored in “z” integer variable. Now we can use “z” to print its value or to other function.
Line no. 14 and 15 does the same job. In line no. 15 we have used an extra variable whereas on line no. 14 we directly printed the value without using any extra variable. This was simply to show you how we can use function in different ways.
FUNCTIONS WITH NO ARGUMENTS BUT RETURNS VALUE.
We may need a function which does not take any argument but only returns values to the calling function then this type of function is useful
1. #include<stdio.h>
2. #include<conio.h>
3. int send()
4. {
5. int no1;
6. printf("Enter a no : ");
7. scanf("%d",&no1);
8. return(no1);
9. }
10. void main()
11. {
12. int z;
13. clrscr();
14. z = send();
15. printf("\nYou entered : %d.", z);
16. getch();
17. }