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

  • Home
  • SEARCH
  • 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 63589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:39:23+00:00 2026-05-10T18:39:23+00:00

I have seen many programs consisting of structures like the one below typedef struct

  • 0

I have seen many programs consisting of structures like the one below

typedef struct  {     int i;     char k; } elem;  elem user; 

Why is it needed so often? Any specific reason or applicable area?

  • 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. 2026-05-10T18:39:23+00:00Added an answer on May 10, 2026 at 6:39 pm

    As Greg Hewgill said, the typedef means you no longer have to write struct all over the place. That not only saves keystrokes, it also can make the code cleaner since it provides a smidgen more abstraction.

    Stuff like

    typedef struct {   int x, y; } Point;  Point point_new(int x, int y) {   Point a;   a.x = x;   a.y = y;   return a; } 

    becomes cleaner when you don’t need to see the ‘struct’ keyword all over the place, it looks more as if there really is a type called ‘Point’ in your language. Which, after the typedef, is the case I guess.

    Also note that while your example (and mine) omitted naming the struct itself, actually naming it is also useful for when you want to provide an opaque type. Then you’d have code like this in the header, for instance:

    typedef struct Point Point;  Point * point_new(int x, int y); 

    and then provide the struct definition in the implementation file:

    struct Point {   int x, y; };  Point * point_new(int x, int y) {   Point *p;   if((p = malloc(sizeof *p)) != NULL)   {     p->x = x;     p->y = y;   }   return p; } 

    In this latter case, you cannot return the Point by value, since its definition is hidden from users of the header file. This is a technique used widely in GTK+, for instance.

    UPDATE Note that there are also highly-regarded C projects where this use of typedef to hide struct is considered a bad idea, the Linux kernel is probably the most well-known such project. See Chapter 5 of The Linux Kernel CodingStyle document for Linus’ angry words. 🙂 My point is that the ‘should’ in the question is perhaps not set in stone, after all.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Find your answer via a similar question right here on… May 11, 2026 at 10:56 am
  • added an answer You need to set the Style.TargetType in order for it… May 11, 2026 at 10:56 am
  • added an answer I haven't looked into any specific guidelines or anything, but… May 11, 2026 at 10:56 am

Related Questions

I have seen many programs consisting of structures like the one below typedef struct
I have seen many examples, with many 'no, you missed something' comments. What is
I have seen many apps that take instrument classes and take -javaagent as a
I have seen this problem arise in many different circumstances and would like to
I have seen simple example Ajax source codes in many online tutorials. What I
Many times I have seen Visual Studio solutions which have multiple projects that share
Haven't seen many Geneva related questions yet, I have posted this question in the
I've seen (and used) code to have a link spawn a javascript action many
I have seen examples of printing from a windows application but I have not
I have seen lots of questions recently about WPF... What is it? What does

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.