NO

Author Topic: Pointers  (Read 3903 times)

David

  • Guest
Pointers
« 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.

JohnF

  • Guest
Pointers
« Reply #1 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

Code: [Select]

#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