0

I'm new to C and new to asking questions. I've read multiple topic and questions on this . If I missed a similar question I'm sorry .

I have an array that I declare in a function. I want to save the adress of the array so later i can find a value in this array from another function.

void vhf_list(int *p_util)
{
    int *full_info=NULL;
    full_info = malloc(60 * sizeof(int)); 

    full_info[0]=576;     //My array
    full_info[1]=577;
    full_info[2]=578;
    full_info[3]=579;
    full_info[4]=580;
    full_info[5]=581;
    full_info[6]=582;
    /*
     rest of array */

    p_util=&full_info[0];
}

And going from there I want to save the adress of this array and re-use it:

void find_apid(int apid, int *p_fctn)
{
    int *p_apid=NULL;
    p_apid = malloc(sizeof(int));
    vhf_list(p_apid);

I've read multiple question trying to grasp the pass by reference but I'm just a bit lost.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Charles A
  • 1
  • 1
  • 2
    `p_util` has local scope. It will not update `p_apid`. Moreover you are loosing (memory leak) mallocated memory of `p_apid`. – LPs Mar 20 '17 at 10:06
  • 1
    C doesn't have pass-by-reference. At all. You can pass an address of something then use it any way you want, but that address is passed *by value*. – Andrew Henle Mar 20 '17 at 10:06
  • Thank you for all the answer. I was wondering if this was marked as duplicate can anyone point me to the duplicate in question? – Charles A Mar 20 '17 at 10:09
  • @CharlesA: Scroll up to the top of your question and you will see a link to the duplicate. – Paul R Mar 20 '17 at 10:10
  • There is no pass by reference in C – ntshetty Mar 20 '17 at 10:21

0 Answers0