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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:10:24+00:00 2026-05-12T13:10:24+00:00

I’m sort of learning C, I’m not a beginner to programming though, I know

  • 0

I’m sort of learning C, I’m not a beginner to programming though, I “know” Java and python, and by the way I’m on a mac (leopard).
Firstly,

1: could someone explain when to use a pointer and when not to?

2:

char *fun = malloc(sizeof(char) * 4);

or

char fun[4];

or

char *fun = "fun";

And then all but the last would set indexes 0, 1, 2 and 3 to ‘f’, ‘u’, ‘n’ and ‘\0’ respectively. My question is, why isn’t the second one a pointer? Why char fun[4] and not char *fun[4]? And how come it seems that a pointer to a struct or an int is always an array?

3:
I understand this:

typedef struct car
{
    ...
};

is a shortcut for

struct car
{
    ...
};
typedef struct car car;

Correct? But something I am really confused about:

typedef struct A
{
    ...
}B;

What is the difference between A and B? A is the ‘tag-name’, but what’s that? When do I use which? Same thing for enums.

4. I understand what pointers do, but I don’t understand what the point of them is (no pun intended). And when does something get allocated on the stack vs. the heap? How do I know where it gets allocated? Do pointers have something to do with it?

5. And lastly, know any good tutorial for C game programming (simple) ? And for mac/OS X, not windows?

PS. Is there any other name people use to refer to just C, not C++? I hate how they’re all named almost the same thing, so hard to try to google specifically C and not just get C++ and C# stuff.

Thanks!!

It was hard to pick a best answer, they were all great, but the one I picked was the only one that made me understand my 3rd question, which was the only one I was originally going to ask. Thanks again!

  • 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-12T13:10:24+00:00Added an answer on May 12, 2026 at 1:10 pm

    My question is, why isn’t the second one a pointer?

    Because it declares an array. In the two other cases, you have a pointer that refers to data that lives somewhere else. Your array declaration, however, declares an array of data that lives where it’s declared. If you declared it within a function, then data will die when you return from that function. Finally char *fun[4] would be an array of 4 pointers – it wouldn’t be a char pointer. In case you just want to point to a block of 4 chars, then char* would fully suffice, no need to tell it that there are exactly 4 chars to be pointed to.

    The first way which creates an object on the heap is used if you need data to live from thereon until the matching free call. The data will survive a return from a function.

    The last way just creates data that’s not intended to be written to. It’s a pointer which refers to a string literal – it’s often stored in read-only memory. If you write to it, then the behavior is undefined.

    I understand what pointers do, but I don’t understand what the point of them is (no pun intended).

    Pointers are used to point to something (no pun, of course). Look at it like this: If you have a row of items on the table, and your friend says “pick the second item”, then the item won’t magically walk its way to you. You have to grab it. Your hand acts like a pointer, and when you move your hand back to you, you dereference that pointer and get the item. The row of items can be seen as an array of items:

    And how come it seems that a pointer to a struct or an int is always an array?

    item row[5];
    

    When you do item i = row[1]; then you first point your hand at the first item (get a pointer to the first one), and then you advance till you are at the second item. Then you take your hand with the item back to you 🙂 So, the row[1] syntax is not something special to arrays, but rather special to pointers – it’s equivalent to *(row + 1), and a temporary pointer is made up when you use an array like that.

    What is the difference between A and B? A is the ‘tag-name’, but what’s that? When do I use which? Same thing for enums.

    typedef struct car
    {
        ...
    };
    

    That’s not valid code. You basically said “define the type struct car { ... } to be referable by the following ordinary identifier” but you missed to tell it the identifier. The two following snippets are equivalent instead, as far as i can see

    1)

    struct car
    {
        ...
    };
    typedef struct car car;
    

    2)

    typedef struct car
    {
        ...
    } car;
    

    What is the difference between A and B? A is the ‘tag-name’, but what’s that? When do I use which? Same thing for enums.

    In our case, the identifier car was declared two times in the same scope. But the declarations won’t conflict because each of the identifiers are in a different namespace. The two namespaces involved are the ordinary namespace and the tag namespace. A tag identifier needs to be used after a struct, union or enum keyword, while an ordinary identifier doesn’t need anything around it. You may have heard of the POSIX function stat, whose interface looks like the following

    struct stat {
      ...
    };
    
    int stat(const char *path, struct stat *buf);
    

    In that code snippet, stat is registered into the two aforementioned namespaces too. struct stat will refer to the struct, and merely stat will refer to the function. Some people don’t like to precede identifiers always with struct, union or enum. Those use typedef to introduce an ordinary identifier that will refer to the struct too. The identifier can of course be the same (both times car), or they can differ (one time A the other time B). It doesn’t matter.

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

Sidebar

Ask A Question

Stats

  • Questions 229k
  • Answers 229k
  • 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
  • Editorial Team
    Editorial Team added an answer In typical Objective-C style, methods that span multiple lines are… May 13, 2026 at 1:44 am
  • Editorial Team
    Editorial Team added an answer I guess your script should more look like this. In… May 13, 2026 at 1:44 am
  • Editorial Team
    Editorial Team added an answer You need to invoke the method using the Dispatcher, calling… May 13, 2026 at 1:44 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

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.