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

The Archive Base Latest Questions

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

When I make my own struct, say: struct myStruct{ int data1; int data2; string

  • 0

When I make my own struct, say:

struct myStruct{
    int data1;
    int data2;
    string data3;
}

I can initialize an instance of type myStruct like this:

myStruct instance1;

So my question is, why am I often seeing “struct” written during the initialization of a struct?
Maybe that’s an inaccurate statement so here is an example of what I mean:

/*This is a tiny program that checks
  to see if a file exists in
  the current working directory. */

#include <sys/stat.h>
#include <iostream>
using namespace std;

const string FILENAME = data.txt;

int main(){

    struct stat fileStatus; //<-- HERE HERE HERE!
    if (FileExists(FILENAME, fileStatus)){
        cout << "File Does Exist" << endl;
    }else{
        cout << "File Does NOT Exist" << endl;
    }

    return 0;
}

bool FileExists(const string & fileName,struct stat & fileStatus){

    bool fileDoesNotExist = stat (fileName.c_str(), &fileStatus);
    return !fileDoesNotExist;
}

>
LINE 13: struct stat fileStatus;

Is this something that was done in C for some reason?
Something with a macro or a typedef?

I just don’t understand why this is the way it is.

  • 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-28T02:05:22+00:00Added an answer on May 28, 2026 at 2:05 am

    This is a C thing; there’s no good reason to continue to do it in C++.1

    In C, struct is part of the typename, e.g.:

    struct foo { int x; };
    

    defines a type called struct foo. In C++, it defines a type called foo. In C, you can usually hide this irritation behind a typedef:

    typedef struct foo { int x; } foo;
    

    1 At least, not in code that couldn’t possibly also be compiled as C (such as the example in your question).

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

Sidebar

Related Questions

can I make my own headers in HTTP request ? e.g. This is normal
Can I make my own jabber server.So that if I run my website xyz
if I make a system call, say struct hostent * gethostbyaddr (const char *addr,
I wanted to make a map with my own struct 'Point2' as key, however
I am making my own WYSIWYG editor. But i can't make any text bold
How can I make my own shell for windows 7? That will run in
it is possible to make own plugin to media center in windows (in .NET)?
is possible to make own help message or attach own event on help option
Should I make my own framework by wrapping up the STL classes and/or Boost
Im looking to make my own implementation of these Identicons or Gravatars found here

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.