
- Forum
- Programming Talk
- C and C++
- Variable Declaration
Variable Declaration
This is a discussion on Variable Declaration within the C and C++ forums, part of the Programming Talk category; I am confused with the declaration of variable passed as argument to a function.I tried a sample C program given ...
-
Variable Declaration
I am confused with the declaration of variable passed as argument to a function.I tried a sample C program given below:
#include <stdio.h>
main()
{
int a=500,c;
c=sampel(a);
printf("c=%d",c);
}
sample(t)
{
int t;
t=t+10;
return(t);
}
The above program gave me error. Is it that I have to declare t before the opening braces of defining the function sample? What is the reason for this?
-
06-06-2007, 03:37 AM #2
- Join Date
- May 2007
- Answers
- 12
int sample(int t)
{
int t;
t=t+10;
return(t);
}
look at the "int sample(int t)" as compared to sample(t)
-
The error you would have got is Re-declaration of t in function sample. Am I right? The reason for this is you have not declared the variable t before the opening brace of function sample().So by default it is assumed as integer variable. But again after the opening brace you have declared again variable t which causes the compiler to throw the error message as re-declaration of
variable t. Remove the declaration and try out and always it is best to declare variables before the opening braces of function calling.
-
12-27-2010, 06:47 AM #4
- Join Date
- Dec 2010
- Answers
- 32
the argument part in the function is the error...
a function got 3 parts return type,name and arguments.....
here the return type will be int,name is sample and argument is int t within brackets
int sample(int t)
{
t=t+10;
return(t);
}
-
Sponsored Ads

Reply With Quote





