Search This Blog

Tuesday, March 22, 2011

a simple file handling programe

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
FILE *even,*odd;
even=fopen("even.txt","w");
odd=fopen("odd.txt","w");
printf("enter the last term till you wanna see even and odd values");
scanf("%d",&a);
for(b=0;b<=a;b++)
if(b%2==0)
fprintf(even,"%d\n",b);
else
fprintf(odd,"%d\n",b);
printf("operation has successfully completed");
getch();
}

Saturday, March 19, 2011

there are two ways to call a function
1.call by value

2.call by function


in call by value variables are sent simply
lets see the example
int a=1,b=2;
func(a,b);

here func is function name and a and b are arguments and here values (a and b) are sent as simple agrument

in call by reference address of a variable is sent while a calling a fuction and in function body we will use of pointer variable to access the value

lets see the example

int a=1,b=2;
int *p,*ptr
p=&a;
ptr=&b;
func(p,ptr);

we can use following also for same task

int a=1,b=2;
func(&a,&b);

here address of variable is sent thats why it is known as call by address

now see the function body,will used in call by reference

void func(int *x, int *y)
{

statement
statement
statement

}

                                 programme for call by reference

#include<stdio.h>
#include<conio.h>
void func(int *,int *); /*function prototype*/ 
void main()
{
int a,b;
a=1;
b=2;
func(&a,&b);
getch();
}
void func(int *x, int *y);
{
int t;
t=*y;
*y=*x;
*x=t;
}