sarithara
asked on
"Type Mismatch in redeclaration"
In my Program
void main()
{
int i=2,j=3,k;
sum(i,j);
}
Error is showing here: sum(int i,int j)
{
int m=i+j;
}
I am getting the error "Type mismatch in Redeclaration". Why?
void main()
{
int i=2,j=3,k;
sum(i,j);
}
Error is showing here: sum(int i,int j)
{
int m=i+j;
}
I am getting the error "Type mismatch in Redeclaration". Why?
can you post your entire code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
int main()
{
int i=2,j=3,k;
k=sum(i,j);
printf("%d\n",k);
return 0;
}
int sum(int p,int q)
{
int m;
m=p+q;
return m;
}
-chirag
{
int i=2,j=3,k;
k=sum(i,j);
printf("%d\n",k);
return 0;
}
int sum(int p,int q)
{
int m;
m=p+q;
return m;
}
-chirag
oh no, i'm too late, Alf already massacre the question =)
Tongue in cheek
Alf, how many lines would it take you to answer the question: 1 + 1?
Tongue out of cheek
Alf, how many lines would it take you to answer the question: 1 + 1?
Tongue out of cheek
/me pretending to be Alf
well, 1+1 is an interesting question, if you go back a bit to the dinosaur age and perform the calculation using dinosaur bone....
....
....< a year later>
.....
and that's how we arrive at the modern age answer that 1+1=2
=)
well, 1+1 is an interesting question, if you go back a bit to the dinosaur age and perform the calculation using dinosaur bone....
....
....< a year later>
.....
and that's how we arrive at the modern age answer that 1+1=2
=)
in C, without a function declaration, you will get this because the function definition will assume type
void sum(void);
and you will get your error. I imagine that you want sum to return an int. simply return m from your current and make the following declaration before you ever USE sum:
int sum(int,int);
int main(...){...}
int sum(int i, int j){...}
Then you won't get this error.
void sum(void);
and you will get your error. I imagine that you want sum to return an int. simply return m from your current and make the following declaration before you ever USE sum:
int sum(int,int);
int main(...){...}
int sum(int i, int j){...}
Then you won't get this error.
sarithara, post your code
I will send the code. Please give time
I wouldn't go back to dinosaurs but I could show the formal answer assuming Peano's postulates ;)
1 + 1 = 1 + s(0) = s(1 + 0) = s(1) = 2
There ;) It was only one line! ;) Of course, if we have to explicitely state the postulates and definitions required it will be more than one single line:
D1. s(0) === 1 (=== means "equal by definition").
D2. s(1) === 2
D3. x + 0 === x
D4. x + s(y) === s(x + y)
this gets:
1 + 1 = 1 + s(0) // since s(0) = 1 by definition D1.
1 + s(0) = s(1 + 0) // since x + s(y) = s(x + y) by definition D4.
s(1 + 0) = s(1) // since 1 + 0 = 1 by definition D3.
s(1) = 2 by definition D2.
so 1 + 1 = 2 QED.
Now, try using those same definitions (actually only D3 and D4 are needed) and show that x + y = y + x for all y and all x. It is possible but it's far from trivial. You can also show that x + (y + z) = (x + y) + z using only D3 and D4.
Good luck ;)
Alf
1 + 1 = 1 + s(0) = s(1 + 0) = s(1) = 2
There ;) It was only one line! ;) Of course, if we have to explicitely state the postulates and definitions required it will be more than one single line:
D1. s(0) === 1 (=== means "equal by definition").
D2. s(1) === 2
D3. x + 0 === x
D4. x + s(y) === s(x + y)
this gets:
1 + 1 = 1 + s(0) // since s(0) = 1 by definition D1.
1 + s(0) = s(1 + 0) // since x + s(y) = s(x + y) by definition D4.
s(1 + 0) = s(1) // since 1 + 0 = 1 by definition D3.
s(1) = 2 by definition D2.
so 1 + 1 = 2 QED.
Now, try using those same definitions (actually only D3 and D4 are needed) and show that x + y = y + x for all y and all x. It is possible but it's far from trivial. You can also show that x + (y + z) = (x + y) + z using only D3 and D4.
Good luck ;)
Alf