Company Logo  
Email: vision1india@gmail.com
 

 

Google
 
 
 

Previous  Next Page

2.6 The Go To Statement

 A goto statement transfers control not only to any other statement within the same function in a C program, but it also allows control to be transferred in and out of blocks.
goto label;


label: statement;

label: {
           statement sequence
           }


2.7 The Break Statement

 The break statement has two uses. It can be used to terminate a case in the switch statement and/or to force immediate termination of a loop, the loop is immediately terminated and the program control is passed to the statement.

 #include<stdio.h>
 main()
 {
 int a,b;
 for(a=1,b=0; a<=100; a++)
 {
 printf("Enter %d number :", a);
 scanf("%d", &b);
 if(b==500) break;
 }

2.8 The Continue statement

 The continue statement causes the next iteration of the loop enclosing it to begin. When this statement is encountered in the loop, control is passed automatically to the beginning of the loop.

 #include<stdio.h>
 main()
 {
 int a,b;
 for(a=1,b=0; a<=100; a++)
 {
 if(a%9==0) continue;
 printf("%d\t", a);
 }
 }


2.9 Array

An array is a group of similar variables that are referred to by a common name. An array can be a single dimensional or multi dimensional. each member of an array is identified by the unique index or subscript assigned to it. An index is a positive integer enclosed in [ ] placed immediately after the array name, without a space between. An index holds only integer values starting from zero.

 #include<stdio.h>
 main()
 {
 int ary[10], a;
 for(a=0;a<10;a++)
 {
 printf("\nEnter value %d", a+1);
 scanf("%d", &ary[a]);
 }
 high=ary[0];
 for(a=1;a<10;a++)
 {
 if(ary[a]>high)
 high = ary[a];
 }
 printf( " Highest value entered was %d", high);
 for(a=0; total=0;a<10; a++)
 {
 total= total +ary[a];
 printf("The average of the element of ary is %d", total/a);
 }
 }

2.10 Two Dimensional Array

 char ary [10][5];
 In two dimensional array it forms a matrix of x and y. Memory addresses also organized   in same manner. Its take [x][y] and for single x, y count all and then x increases one time.

3.1 Function

When a large program modules in smaller parts then every part is known as function.
 
type_specifier  function_name(arguments)
 {
 body_of_the_function
 }

 #include<stdio.h>
 main()
 {
 int a;
 for(a=1;a<=10;a++)
 printf("\nSquare of %d is %d", a, squarer(a));
 }
 squarer(int x)
 {
 int y;
 y=x*x;
 return(y);
 }

A function protype is a function declaration that specifies the data types of the arguments.

3.2 Local Variables

Local variables are also known as automatic variables, as the keyword auto can be used to declare them. They can be referred to only by statements that are inside the code block, which declares them.

 {
 char ch;
 ch='x';           /* ch is a local variable   */
 ......
 }

3.3 Global Variables

Global variables are visible to the entire program and can be used by any piece of code. They are declared outside any function of a program and hold their value throughout the program execution. These variables can be declared either outside the main() or declared anywhere before its first use.


 int ab;        /* ab is the global variable   */
 main()
 {
 ab=10;

 }

 void xy()
 {
 ab=20;
 }

3.4 Function Call By Value and Call By Reference

In C, by default all the function argument are passed by value. When argument are passed to the called function, the values are passed through temporary variables. The called function cannot access the actual memory location of the original variable and therefore cannot change its value.

In Call By Reference, the function is allowed access to the actual memory location of the variable passed as an argument and therefore can be change the value of the arguments of the calling routine.


4.1 Recursive function

Recursion is a process of defining something in terms of itself. A function is said to be recursive if a statement in the body of the function calls itself.

 #include<stdio.h>
 main()
 {
 int n;
 long int a;
 long int fibo(int n);
 clrscr();
 printf("Enter Numbers for Fibonacci series: \n");
 scanf("%d", &n);
 a = fibo(n);
 printf("The %th fibonacci no. is \n",n,a);
 }
 long int fibo(int m)
 {
 if(m<=2)
 return(1);
 else
 return (fibo(m-1) + fibo (m-2));
 }

4.2 Storage Classes

We already read about Automatic or Local Variables & Global Variables (Extern variable) previously. See both section.

4.2.2 Static Variable

The static variable are permanent variable within their own functions or files. They are not known outside their function or file but they maintain their values between calls.

 #include<stdio.h>
 main()
 {
 incre();
 incre();
 incre();
 }
 incre()
 {
 static char var=65;
 printf("\nThe character stored in var is %c", var++);
 }

  > Register Variables

 When any variable created and stored in computers register memory then it is called as Register Variable. Register keyword is used to create register variable. If the register is not free then it is created as local variable.

 register int a;

    Previous  Next Page

 
 

 

 

Copyright 2007 Tutorials Web Designer