-5

Can someone please explain me the purpose of func(&_) and void? I am not sure how the whole program works.

    void func(int *xp);

    int
    main(void)
    {
        int x, y;

        x = 5; 
        func(&x);
        y = x-3;
        func(&y);
        printf("%4d%4d\n", x, y);
        return(0);
    }

    void
    func(int *xp)
    {
        int y;

        y = *xp * 2;
        *xp = y - 3;
    }
Kache
  • 15,647
  • 12
  • 51
  • 79

1 Answers1

0

Your function demands a pointer argument. If you want to pass a non-pointer variable to that function call, you must provide it's address, using the & notation.

Andro
  • 2,232
  • 1
  • 27
  • 40