using of pointer

This is a discussion on using of pointer within the C Programming forums, part of the General Programming Boards category; Hi, I have write out a code that use a pointer and print out the sum of two squared value. ...

  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,006
    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, 11:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 04:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 08:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 04:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21