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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:23:14+00:00 2026-05-20T05:23:14+00:00

So I have a structure of unknown size as follows: typedef struct a{ int

  • 0

So I have a structure of unknown size as follows:

typedef struct a{
int id;
char *name;
enum job {builder=0, banker, baker};
} person;

person p;

and I want to count how many entries are in the struct through some sort of loop. I’m sure this is very simple and I’m just not thinking about it correctly but I can’t seem to figure out how I would this without knowing its size.

So presumably I can’t use:

for(i=0; i<x; i++) //where x is the size of the struct
{
   if(p.id!=0)
      count++;
}

what am i missing here?

  • 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-20T05:23:15+00:00Added an answer on May 20, 2026 at 5:23 am

    A struct is a template for laying out memory.

    A variable is a name that has a value, sometimes that value is a bunch of memory laid out according to a struct.

    Sometimes that variable is a pointer (possibly pointing to to a bunch of structs laid out in memory). Sometimes that variable is an array (possibly of structs).

    Since you didn’t indicate more than one “person struct” when defining the variable p, you only have one struct to count in “p”

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

Sidebar

Related Questions

I have a structure: typedef struct stock { const char* key1p2; // stock code
I have a dictionary of unknown depth and structure. It might contain more dictionaries,
I have a structure like this struct structure { BaseObject &A; //BaseObject has a
I have to change unknown contents of XML. The structure and content itself is
I have a Java object with some unknown structure. Now I want to output
I have a structure named Foo which contains a unique_ptr struct Foo { std::unique_ptr<Bar>
I have structure like this. <ul class=gallerylist> <li> <image ...> <input ...> </li> <li>
I have menu structure as show here . All item have a background img.
I have below structure <div class=mybox> <div id=imageslide> <a href=><img src=url /></a> </div> </div>
I have this structure: Activity A has a ViewPager. The pages of a ViewPager

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.