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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:21:57+00:00 2026-05-28T20:21:57+00:00

Think of a pointer-datatype, for instance to a floating-pointer number. typedef float* flPtrt; How

  • 0

Think of a pointer-datatype, for instance to a floating-pointer number.

typedef float* flPtrt;

How would I allocate an array of 3 elements in the local scope? I guess using malloc and free withing the same scope produces overhead, but what’s the alternative?

void foo() {
    flPtrt ptr = malloc(sizeof(float)*3);
    // ...
    free(ptr);
}
  • 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-28T20:21:58+00:00Added an answer on May 28, 2026 at 8:21 pm

    I think what your’e looking for is the alloca() function.
    I’m not sure it’s standard C, but it exists in GNU, and it worked on my visual studio.
    So this is how you use it:

    int n = 5;
    int* a = (int*) alloca(sizeof(int) * n);
    

    It creates an array of elements on the stack (rather than on the heap with malloc).
    Advantages: less overhead, no need to free manually (when you return from your method, the stack folds back and the memory is lost)
    Disadvantage: If you want to return a pointer from a method NEVER use alloca, since you will be pointing at something that no longer exists after exiting the function. One can also argue that the stack is usually smaller than the heap, so if you want larger space use malloc.
    See more here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do pointer to pointers work in C? Hello, Altough I think
I (think I) understand that you can only retrieve the size of an array
In my program I would like to manipulate boost::filesystem::path elements of a vector in
Besides remembering the address of the pointer of the object, I think the OS
I think we all understand the necessity of delete when reassigning a dynamically-allocated pointer
I have a problem with a template and pointers ( I think ). Below
I understand the overall meaning of pointers and references(or at least I think i
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think the file that is produced is an .asm file, any idea how

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.