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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:29:50+00:00 2026-05-16T07:29:50+00:00

gcc 4.4.4 c89 Pointers are not the same as arrays. But arrays can decay

  • 0

gcc 4.4.4 c89

Pointers are not the same as arrays. But arrays can decay into pointers.

I was just using memset which first parameter is a pointer. I would like to initialize my structure array.

i.e.

struct devices
{
    char name[STRING_SIZE];
    size_t profile;
    char catagory;
};

struct devices dev[NUM_DEVICES];

memset(dev, 0, (size_t)NUM_DEVICES * sizeof(*dev));

dev == &dev[0]

But should I pass the first parameter has this:

 memset(&dev, 0, (size_t)NUM_DEVICES * sizeof(*dev));

Many thanks for any advice,

  • 1 1 Answer
  • 1 View
  • 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-16T07:29:51+00:00Added an answer on May 16, 2026 at 7:29 am

    What you have:

    memset(dev, 0, (size_t)NUM_DEVICES * sizeof(*dev));
    

    is fine – you pass a pointer to the first element of the array, and the size of the array. However, the (size_t) cast is unnecessary (sizeof has type size_t, so it will cause the correct promotion) and I find that dev[0] is clearer than *dev in this case:

    memset(dev, 0, NUM_DEVICES * sizeof dev[0]);
    

    Alternatively, you can use &dev as the address. In this case, it is probably clearer to use sizeof dev – the size of the whole array:

    memset(&dev, 0, sizeof dev);
    

    I say that this is clearer, because it’s generally best to have the first parameter be a pointer to the type that’s the subject of sizeof in the last parameter: the memset() should look like one of these forms:

    memset(p, ..., N * sizeof p[0])
    memset(&x, ..., sizeof x)
    

    Note however that this last one only works if dev really is an array – like it is in this case. If instead you have a pointer to the first element of the array, you’ll need to use the first version.

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

Sidebar

Related Questions

gcc 4.4.4 c89 I am just wondering is it worth passing a const into
gcc 4.4.2 c89 I was just working on some pointers. However, with the program
Using gcc 4.4.3 c89: I am just working on the following code below: I
at first excuse me for not providing any code, but it's hard to just
gcc c89 I am just looking to link against the below shared library. I
gcc (GCC) 4.6.3 c89 apache runtime portable libraries Hello, Just a simple question I
gcc (GCC) 4.6.3 c89 Hello, I am just wondering if this is the best
gcc 4.4.3 c89 I am just getting started with log4c. However, there is very
gcc 4.4.4 c89 I understand pointers ok. However, I am stepping up to pointer
c89 gcc 4.7.4 I was just experimenting with macros like these: #define LOG_INFO_1(fmt, ...)

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.