Thread: using of pointer

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    49

    using of pointer

    Hi,
    I have write out a code that use a pointer and print out the sum of two squared value. I am not sure where i go wrong in the code, can anyone correct my error??
    Thanks.

    Code:
    #include <stdio.h>
    
    int sumsq(int *a, int *b);
    
    int main(void)
    {
      printf("Sum of 4 square and 2 square (passed by reference) is %d", sumsq(4, 2));
      int sumsq();
      return(0);
    }
    
    int sumsq(int *a, int *b)
    {
      int *sum;
      *sum = (*a * *a) + (*b * *b);
      printf("%d", *sum);
      return (*sum);
    }
    diana --> programming is tough

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Contrast with:
    Code:
    #include <stdio.h>
    
    int sumsq(int *a, int *b);
    
    int main(void)
    {
       int x = 4, y = 2;
       printf("Sum of 4 square and 2 square (passed by reference) is %d", sumsq(&x, &y));
       return(0);
    }
    
    int sumsq(int *a, int *b)
    {
       int sum;
       sum = (*a * *a) + (*b * *b);
       printf("%d", sum);
       return(sum);
    }
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    49
    Thanks.... i got it...
    diana --> programming is tough

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM