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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:28:52+00:00 2026-05-24T08:28:52+00:00

EDIT: Thank you very much for your responses. I understand this properly now! I

  • 0

EDIT: Thank you very much for your responses. I understand this properly now!

I am trying to learn more on C pointers. Tinkering around, I am questioning the difference between two actions I am using.

This code seems to work at first glance, but I am not sure of what’s the difference, and if any of these two approaches is wrong in some way.

I’d like to know what’s the difference between the two pieces of code, when I should I pass the adress, and when a pointer to an array?

Is any of the pieces wrong? If so, what would be the proper way?

having a simple struct grid pretty much like struct grid { int val; } (for demonstration purposes)

First piece of code. Passing address of the pointer to the array.

    void set (mygrid *grid, int foo){
        grid->bar = foo; //should this be '*grid->bar?' But this seems to work properly.
    }

    void main(){
        int i;
        int* array;
        int max = 24;

        array = malloc(sizeof(grid) * max);

        for(i = 0; i < max; i++){
            set(&array[i], 0);
        }
    }

Second piece of code. I am not entirely sure why this works, but the compiler doesn’t output any warning.
I am supposed to be passing the pointer to the start of the array like this?

    void set(mygrid *grid, int foo){
        int i; int max = 24; //so this example code compiles :P

        for(i = 0; i < max; i++){
            grid[i].bar = foo;
        }
    }

    void main(){
        int* array;
        int max = 24;

        array = malloc(sizeof(grid) * max);
        set(array, 0); //Why not &array?
    }
  • 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-24T08:28:52+00:00Added an answer on May 24, 2026 at 8:28 am

    Passing an array decays into a pointer that points to the first member of the array, just like &array[0].

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

Sidebar

Related Questions

EDIT: Thank you so much for your answers, you really amaze me with so
EDIT: I have fixed all but two warnings now, so thank you all for
Code as reference: http://jsbin.com/aboca3/2/edit In this example above (thank you SLaks) I am truncating
EDIT2: Thank you all for your help! EDIT: on adding @staticmethod, it works. However
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
Edit 2: Actually SomeEventHandler is more concise than OnSomeEventHandler : If I let Visual
More often than I like when designers edit some of our sites' pages, they
EDIT AGAIN: the solution was probably different from my original question. Thanks everyone very
I'm trying to create a custom tweet button with a popup, this part works.
I'm very new to multi-threading and for some reason this class is giving me

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.