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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:04:43+00:00 2026-05-15T19:04:43+00:00

?? fun() { int a[3]={3,3,4}; return &a; } what could be the compatible return

  • 0
?? fun()
{
   int a[3]={3,3,4};
   return &a; 
}

what could be the compatible return type. Here the pointer is pointing to the array of 3 integers not just the pointer which points to integer array.
Aim is to return a pointer to array of 3 integers.

  • 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-15T19:04:44+00:00Added an answer on May 15, 2026 at 7:04 pm

    Everyone else has already told you why you shouldn’t do this as it is written, but here are the types you are interested in.

    Given a declaration int a[3], the type of the expression &a is int (*)[3] (not int **), or “pointer to 3-element array of int”, such as

    void f()
    {
      int a[3] = {1,2,3};
      int (*aptr)[3] = &a;
      ...
    }
    

    and the signature for a function returning that type would be int (*fun())[3] {...}.

    One other option nos didn’t show is this:

    int (*fun())[3]
    {
      int (*aptr)[3] = malloc(sizeof *aptr);
      if (aptr)
      {
        (*aptr)[0] = 1; // array pointer must be deferenced before applying
        (*aptr)[1] = 2; // the subscript. 
        (*aptr)[2] = 3;
      }
      return aptr;
    }
    

    although this isn’t terribly useful; you don’t normally see allocations of single, fixed-size arrays like this. Somewhat more useful is allocating an array of those arrays:

    int (*fun(size_t count))[3]
    {
      int (*aptr)[3] = malloc(sizeof *aptr * count);
      if (aptr)
      {
        size_t i;
        for (i = 0; i < count; i++)
        {
          aptr[i][0] = 1; // aptr[i] implicitly dereferences aptr, so
          aptr[i][1] = 2; // there's no need for an explicit dereference
          aptr[i][2] = 3; // here.
        }
      }
      return aptr;
    }
    

    Even so, if somebody needs to allocate a fixed-size array type, they usually hide it behind a typedef:

    typedef int fixedSizeRecord[SOME_SIZE];
    ...
    fixedSizeRecord *fun(size_t count)
    {
      fixedSizeRecord *aptr = malloc(sizeof *aptr * count);
      if (aptr)
      {
          // initialize contents as necessary
          for (size_t i = 0; i < count; i++)
            for (j = 0; j < sizeof *aptr / sizeof *aptr[0]; j++)
              aptr[i][j] = ...;
      }
      return aptr;
    }
    

    Abstraction is a good thing.

    I’ve put up several iterations of this table before; you might find it handy.

    Declaration: T a[N];
    
    Expression        Type        Decays To        Value
    ----------        ----        ---------        -----
             a        T [N]       T *              Address of first element in a
            &a        T (*)[N]    n/a              Address of a (same value as above,
                                                     but different type)
            *a        T           n/a              Same as a[0]
          a[i]        T           n/a              Value at index i
         &a[i]        T *         n/a              Address of value at index i
      sizeof a        size_t                       Total number of bytes in a
                                                     (N * sizeof T)
    sizeof a / 
      sizeof *a       size_t      n/a              Number of elements in a (N)
    
    Declaration: T a[N][M];
    
    Expression        Type        Decays To        Value
    ----------        ----        ---------        -----
             a        T [N][M]    T (*)[M]         Address of first element in a[0]
            &a        T (*)[N][M] n/a              Address of a (same value as above,
                                                     but different type)
            *a        T [M]       T *              Same as a[0]
           a[i]       T [M]       T *              Address of first element in array 
                                                     at index i
          &a[i]       T (*)[M]    n/a              Address of array at index i (same 
                                                     value as above, but different 
                                                     type)
          *a[i]       T           n/a              Same as a[i][0]
        a[i][j]       T           n/a              Value at a[i][j]
       &a[i][j]       T *         n/a              Address of value at index i,j
       sizeof a       size_t      n/a              Total number of bytes in a
                                                     (N * M * sizeof T)
    sizeof a /
      sizeof *a       size_t      n/a              Number of subarrays in a (N)
    sizeof a[i]       size_t      n/a              Total number of bytes in a[i]
                                                     (M * sizeof T)
    sizeof a[i] /
      sizeof *a[i]    size_t      n/a              Number of elements in a[i] (M)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 467k
  • Answers 467k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Modify your code by adding one line to the method:… May 16, 2026 at 2:11 am
  • Editorial Team
    Editorial Team added an answer Option 2 is the standard implementation of such a relationship.… May 16, 2026 at 2:11 am
  • Editorial Team
    Editorial Team added an answer I'm guessing you want something like this: private WebView mWebView;… May 16, 2026 at 2:11 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.