Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:37:47+00:00 2026-06-11T01:37:47+00:00

I have pointers in main for which I don’t know it’s size. A function

  • 0

I have pointers in main for which I don’t know it’s size. A function returns this pointer to main. Inside the function I can calulate the size of pointer and hence need to store values in them and return them to main. How to modify/allocate memory in this case.

int main()
{
    int *row_value, *col_value;
    col_row_value(row_value,col_value);
    ...
    return(0);
}

void col_row_value(row_value,col_value)
{
    // how to allocate/modify memory for row_value and col_value and store data
    // for example would like to allocate memory here
    int i;
    for(i=0;i<10;i++) {
        row_value[i]=i;
        col_value[i]=i;
    }
}

I tried something like this,it doesn’t work

int main()
{
    int *row_value, *col_value;
    row_value=NULL;
    col_value=NULL;
    col_row_value(&row_value,&col_value);
    ...
    return(0);
}

void col_row_value(int **row_value,int **col_value)
{
    // how to allocate/modify memory for row_value and col_value and store data
    // for example would like to allocate memory here
    int i;
    *row_value=(int*)realloc(*row_value,10*sizeof(int));
    *col_value=(int*)realloc(*col_value,10*sizeof(int));
    for(i=0;i<10;i++) {
        row_value[i]=i;
        col_value[i]=i;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:37:48+00:00Added an answer on June 11, 2026 at 1:37 am

    This:

    *row_value=(int*)realloc(row_value*,10*sizeof(int));
    

    should be:

    *row_value = realloc(*row_value,10*sizeof(int));
                     /** ^ **/
    

    Note the cast is unnecessary. Assign the result of realloc() to a temporary pointer in case the reallocation fails which would mean the original memory would be inaccessible.

    int* tmp = realloc(*row_value, 10 * sizeof(*tmp));
    if (tmp)
    {
        *row_value = tmp;
    }
    

    Note the for loop does not assign a value to the first element in row_value or col_value:

    for(i=1;i<10;i++)
    

    as it starts at index 1 and the assignments within the for should be:

    (*row_value)[i] = i;
    (*col_value)[i] = i;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C function in which I have 4 pointers and each of
I know that javascript doesn't have pointers in terms of a variable referring to
I have two pointers, char *str1; int *str2; If I look at the size
I have to make a horizontal month slider which will have two pointers which
I have a Cocoa app with a ManMenu.xib, in which the main menu is
In my application I have two threads a main thread which is busy most
I am having trouble getting this to work. I have variables initiated in main
I have a function which takes in a list of characters and generates the
I have read from the Wikipedia that: References cannot be null, whereas pointers can;
I have a structure which contains some elements, i free the memory of this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.