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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:06:50+00:00 2026-05-21T22:06:50+00:00

I am studying for a final tomorrow in C, and have a question regarding

  • 0

I am studying for a final tomorrow in C, and have a question regarding the sizeof operator.

Let’s say the size of an int is 32 bits and a pointer is 64 bits.

If there were a function:

int
foo (int zap[])
{
    int a = sizeof(zap);
    return a;
}

Because zap is a pointer, foo would return 8, as that’s how many bytes are needed to store this particular pointer. However, with the following code:

int zip[] = { 0, 1, 2, 3, 4, 5 };
int i = sizeof(zip);

i would be 6 * sizeof(int) = 6 * 4 = 24

Why is it that sizeof(zip) returns the number of elements times the size of each element, whereas sizeof(zap) returns the size of a pointer? Is it that the size of zap is unspecified, and zip is not? The compiler knows that zip is 6 elements, but doesn’t have a clue as to how large zap may be.

  • 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-21T22:06:51+00:00Added an answer on May 21, 2026 at 10:06 pm

    This is sort of an asymmetry in the C syntax. In C it’s not possible to pass an array to a function, so when you use the array syntax in a function declaration for one of the parameters the compiler instead reads it as a pointer.

    In C in most cases when you use an array in an expression the array is implicitly converted to a pointer to its first element and that is exactly what happens for example when you call a function. In the following code:

    int bar[] = {1,2,3,4};
    foo(bar);
    

    the array is converted to a pointer to the first element and that is what the function receives.

    This rule of implict conversion is not however always applied. As you discovered for example the sizeof operator works on the array, and even & (address-of) operator works on the original array (i.e. sizeof(*&bar) == 4*sizeof(int)).

    A function in C cannot recevive an array as parameter, it can only receive a pointer to the first element, or a pointer to an array… or you must wrap the array in a structure.

    Even if you put a number between the brackets in the function declaration…

    void foo(int x[4])
    {
        ...
    }
    

    that number is completely ignored by the compiler… that declaration for the compiler is totally equivalent to

    void foo(int *x)
    {
        ...
    }
    

    and for example even calling it passing an array with a different size will not trigger any error…

    int tooshort[] = {1,2,3};
    foo(tooshort);  /* Legal, even if probably wrong */
    

    (actually a compiler MAY give a warning, but the code is perfectly legal C and must be accepted if the compiler follows the standard)

    If you think that this rule about arrays when in function arguments is strange then I agree, but this is how the C language is defined.

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

Sidebar

Related Questions

I'm studying for a final exam and I stumbled upon a curious question that
I am studying for a final and have a few questions about RMI and
while studying some security things, there was a question that one can guess the
Studying the K&R book in C I had a few questions regarding complicated pointer
I'm studying for my final exams in my CS major on the subject distributed
I'm currently studying for a CS course's final exam and I've run into a
While studying about JMX, I have seen one of the important feature of it
While studying Java tutorials, Reflection and Late Binding have confused me. In some tutorials,
While studying C# in ASP.net I have trouble understanding several classes. In which scenario
I started studying Haskell one week ago and have one strange problem. I created

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.