Thread: pointers

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    6

    pointers

    /*Write a function called add_two() It will receive three pointers to floats
    It will add the numbers pointed to by the first two pointers and store their
    sum in the location pointed to by the third pointer. In main(), define j,k, and
    m Scan in j and k, send their addresses to add_two(), and have main() print
    the address of m and its value that is in it from add_two().*/

    #include <stdio.h>
    void add_two (float*,float*,float*);
    void main (void)
    {
    float j,k,m;
    printf("Enter a integer for j and k: ");
    scanf("%d %d",&j,&k);
    add_two(&j,&k,&m);
    printf("%p %d",&m,m);
    scanf("%d",&k);

    }
    void add_two(float *a,float *b,float *c)
    {
    *c = *a + *b;
    getchar();
    }

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Looks close...

    Couple problems.

    1st, main returns an int, not void.
    Code:
    printf("%p %d",&m,m); 
    scanf("%d",&k);
    These aren't right. the scnaf is unecessary, and the printf statement is wrong - you don't want %p, you want %d.

    getchar isn't necessary in addtwo.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM