Thread: Simple issue with pointer changing value when function is called.

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    Simple issue with pointer changing value when function is called.

    Hello, I have a function that receives a pointer

    void ordenar(int, int, ListaInt *);

    So I call it from my main():

    ordenar(p,n,&a);

    value of &a is 0x28FEE4


    So far so good, problem arises when inside ordenar() I call

    bubbleSort(p, q, &a);

    inside bubblesort &a becomes somehow...
    0x28FED8

    Any ideas?

    Thank you for reading, I appreciate it.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You probably need to pass a to bubbleSort(), not &a.

    It is usually a good idea to use more descriptive names than p, n, and a for your variables too.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yes, to just pass an input pointer onto another function expecting the same type of pointer, you just drop the &

    bubbleSort(p, q, a);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    Thank you!

    It is usually a good idea to use more descriptive names than p, n, and a for your variables too.


    Yes I agree, wasn't my choice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with simple function pointer
    By livin in forum C Programming
    Replies: 1
    Last Post: 12-01-2011, 09:00 PM
  2. function pointer issue
    By drshmoo in forum C Programming
    Replies: 7
    Last Post: 09-22-2011, 03:04 PM
  3. Using objdump to see a called function
    By Angus in forum C Programming
    Replies: 3
    Last Post: 03-17-2009, 01:33 PM
  4. Changing pointer inside function?
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2008, 05:10 AM
  5. Function Called With Same Arguments Again & Again
    By unbuonragazzo in forum C++ Programming
    Replies: 5
    Last Post: 06-20-2008, 03:17 PM