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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:50:25+00:00 2026-06-07T05:50:25+00:00

In a dynamically created array of structs, what does every entry of the struct

  • 0

In a dynamically created array of structs, what does every entry of the struct get initialized to?

Details:
If we create a dynamic array of floats like so:

float* arr = ( float* ) malloc ( 100 * sizeof ( float ) );

then the array can be populated by anything (see here). But I am having trouble wrapping my head around what happens when we substitute structs in for floats like so

typedef struct
{
   float x = 123.456;
} foo;

foo* arr = ( foo* ) malloc ( 100 * sizeof ( foo ) );

Are all the entries of the array arr created with fully initialized foo structs or do I have to go around and manually update the x value?

  • 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-07T05:50:26+00:00Added an answer on June 7, 2026 at 5:50 am
    typedef struct
    {
       float x = 123.456;
    } foo;
    

    You cannot have default values in structure types. This is not valid C code.

    Objects allocated by malloc have an indeterminate value.

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

Sidebar

Related Questions

Can c++ create array of pointers to different classes dynamically loaded from dll? ps.without
I need to create an array of label and text boxes dynamically. I have
Given that EVAL is Evil how do I create an Array name dynamically: I
I'm trying to create a function that would dynamically allocate an array, sets the
I am struct to a very basic question. I want to create dynamically an
I am looking to create a set of dynamically created arrays stored inside an
This is a class assignment that must be done using a dynamically created array
I want to fill in a dynamically created array once only at the top
I have the need to store a list/collection/array of dynamically created objects of a
So I have a dynamically created playlist that users create by searching for songs.

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.