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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:56+00:00 2026-06-04T04:12:56+00:00

I was trying to return an array from child_prog() to main() . The code

  • 0

I was trying to return an array from child_prog() to main(). The code looks like this:

#include<stdio.h>
#include<stdlib.h>
int* child_prog(int some_input);

void main(void){
  int C[10];
  int some_input;
  C = child_prog(some_input);
}

int* child_prog(int some_input){
  static int out[10];
  // ...
  // ... some wizardry
  return out;
}

Now the compiler generates an error saying that it can not assign to C (which is an int[] type) the value returned from child_prog (which is an int* type). Indeed, the program works fine when I make C an int* and malloc it 10 ints of memory. But I don’t understand why the compiler can’t assign to C (an array defined as C[10] and hence a pointer) the value returned from child_prog (an array defined as static int out[10] and hence again a pointer).

  • 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-04T04:12:57+00:00Added an answer on June 4, 2026 at 4:12 am
    1. You cannot assign to an array. You need to memcpy it.
    2. int* != int[] while the first is a pointer that might point to an int of a sequence of ints, the second is a sequence of ints
    3. You can use int *C; and pass the length of the array (if unknown at compile time) as an out parameter.
    4. static int out[10]; is not a malloced, but static.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to return the ajax success array from one function to another. For
I am trying to write some code to return an array in C#, but
I'm trying to return a 2d array from call(), I'm having some issues. My
I am trying to return an array Data Member from one smaller 2D Array
I am trying to return an array from c# to classic asp using com.
I'm fairly new to PHP and I am trying to return an array from
I am trying to return mime types from an array. I have these strings
Iam trying to return json data from codeigniter view. but my code is not
I'm trying to return data as an array to my .ajax function on success
I'm trying to query using Castle and return a strong-typed array or IList for

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.