Pelles C forum

Pelles C => General discussions => Topic started by: David on September 29, 2004, 08:07:32 AM

Title: Pointers
Post by: David on September 29, 2004, 08:07:32 AM
Hi i wrote this piece of code.
#include <stdio.h>
#include <math.h>

int pointer(int *a, int *b);
int main()
{
   int a=4;
   int b=7;
   int *a;
   int *b;
   a = &a;
   b = &b;
   pointer(a,b);
   return 0;
}
int pointer(int *a, int *b);
{
   int result;
   result= *a + *b;
   printf("%lf\n",result);
   return 0;
}
it's ment to take the values of a and b and plus then and print the result out. I can'nt seen to get it working i spent a lot of time on it I will ve Higlly obliged if someone can point out the mistaked because i can'nt seem to pick it up.
Title: Pointers
Post by: JohnF on September 29, 2004, 08:34:22 AM
A couple of things. You were designating two 'a' and 'b' vars, you need aa and bb. Second your printf used %lf, you need %d


#include <stdio.h>
#include <math.h>

int pointer(int *a, int *b);
int main(void)
{
int a=4;
int b=7;
int *aa;
int *bb;
aa = &a;
bb = &b;
pointer(aa,bb);
return 0;
}

int pointer(int *a, int *b)
{
int result;
result= *a + *b;
printf("%d\n",result);
return 0;
}


John