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 6766337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:06+00:00 2026-05-26T14:49:06+00:00

The original question is the problem of my confusion, sorry. #include <stdio.h> #include <stdlib.h>

  • 0

The original question is the problem of my confusion, sorry.

#include <stdio.h>
#include <stdlib.h>

void func(int **p_in1, int **p_in2, int **p_in3){
  int *p_temp1 = (int *)malloc(5*sizeof(int));
  int *p_temp2 = (int *)malloc(5*sizeof(int));
  int *p_temp3 = (int *)malloc(5*sizeof(int));
  int i;
  for(i = 0; i < 5; i++){
       p_temp1[i] = i+1;
       p_temp2[i] = i+2;
       p_temp3[i] = i+3;
  }
  *p_in1 = p_temp1;
  *p_in2 = p_temp2;
  *p_in3 = p_temp3;
}

int main(){
    int *p_out1 = NULL, *p_out2 = NULL, *p_out3 =NULL;
    int i;
    func(&p_out1, &p_out2, &p_out3);

    for(i = 0; i < 5; i++){
        printf("%d", p_out1[i]);
        printf(" ");
        printf("%d", p_out2[i]);
        printf(" ");
        printf("%d\n", p_out3[i]);
    }

   free(p_out1);
   free(p_out2);
   free(p_out3);
   p_out1 = NULL;
   p_out2 = NULL;
   p_out3 = NULL;
   return 0;
}

I want to make the “func” much shorter by just use one para. How can I put the “p_in1, p_in2, p_in3” together in continuous memory space?

  • 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-05-26T14:49:06+00:00Added an answer on May 26, 2026 at 2:49 pm

    Now that you’ve edited in the output that you wanted, the question can be answered.

    Change your print loop to this:

    for(i = 0; i < 5; i++){
        printf("%d", p_out1[i]);
    }
    printf(" ");
    for(i = 0; i < 5; i++){
        printf("%d", p_out2[i]);
    }
    printf(" ");
    for(i = 0; i < 5; i++){
        printf("%d", p_out3[i]);
    }
    

    This will output:

    12345 23456 34567
    

    In your original code, you were interleaving the 3 arrays. What you wanted was to print each one separately.

    EDIT: As for your second question, you can combine p_out1, p_out2, and p_out1 into an array.

    Here’s your code with this done:

    void func(int **p_in){
      int *p_temp1 = (int *)malloc(5*sizeof(int));
      int *p_temp2 = (int *)malloc(5*sizeof(int));
      int *p_temp3 = (int *)malloc(5*sizeof(int));
      int i;
      for(i = 0; i < 5; i++){
           p_temp1[i] = i+1;
           p_temp2[i] = i+2;
           p_temp3[i] = i+3;
      }
      p_in[0] = p_temp1;
      p_in[1] = p_temp2;
      p_in[2] = p_temp3;
    }
    
    int main(){
        int *p_out[3];
        func(p_out);
    
        int i;
        for(i = 0; i < 5; i++){
            printf("%d", p_out[0][i]);
        }
        printf(" ");
        for(i = 0; i < 5; i++){
            printf("%d", p_out[1][i]);
        }
        printf(" ");
        for(i = 0; i < 5; i++){
            printf("%d", p_out[2][i]);
        }
    
       free(p_out[0]);
       free(p_out[1]);
       free(p_out[2]);
    
       return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've editing this original question as I think I've narrowed down the problem... I
MAJOR EDIT: Problem was solved after reading Will Dean's comment. The original question is
(I rewrite the original question. The problem is the same.) The above example code
Edit: Below is my original question. After solving my problem, I thought I'd re-edit
Original question is below. I fixed my problem. I had the same view controller
The original question is the following: Where A=1 AND A=2 returns 0 row problem
So the problem changed from what it was, i'll leave the original question below
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
Original Question I want to be able to generate a new (fully valid) MP3
Original Question I am looking for a function that attempts to quantify how distant

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.