Answers:
A function (whose return type is NOT void), has to return something of the appropriate return type (e.g. int) using a return statement. Otherwise the compiler will show an error.
This is possible with two different techniques.
1) Using Global Variable and
2) Using Pass by Address Method
Example-1:
int k;
void increment();
int main()
{
increment();
printf("%d",k);
return 0;
}
void increment()
{
k=k+1;
}
Example-2:
void increment(int *);
int main()
{
int k=5;
increment(&k);
printf("%d",k);
return 0;
}
void increment(int *p)
{
*p = *p + 1;
}
I am using neither of these ways but still it is working
#include <stdio.h>
int square(int n)
{
int s;
s=n*n;
}
int main()
{
int m,r;
scanf("%d",&m);
r =square(m);
printf("Square of number = %d",r);
return 0;
}
int square(int n)
{
int s;
s=n*n;
}
int main()
{
int m,r;
scanf("%d",&m);
r =square(m);
printf("Square of number = %d",r);
return 0;
}
Yes, True but it return the last used parameter value (value in AL).
So your functions return type and parameters must be matched accordingly.
like
int test(int p,int q, int r)
{
int a,b,c;
a=p;
b=q;
c=r;
}
called like:
test(1,2,3);
it will return 3.
Login to add comment
Use the following program to avoid warning
----------------------------------------------------------
nt add(int a,int b)
{
int c = a + b;
return c;
}
int main()
{
int sum;
sum = add(5,4);
printf("Sum of a and b is %d\\n",sum);
return 0;
}
Dr.R.Senthilkumar,IRTT,Tamilnadu
int square(int n)
{
int s;
s=n*n;
}
int main()
{
int m,r;
scanf("%d",&m);
r =square(m);
printf("Square of number = %d",r);
return 0;
}
Login to add comment