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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:15:26+00:00 2026-06-12T22:15:26+00:00

The normal method I use to pass one-dimensional array to a function is as

  • 0

The normal method I use to pass one-dimensional array to a function is as follows.

#include <stdio.h>
#define ARRAY_SIZE 5 

void function(int *ptr_array, int size) 
{
  int index;
  printf("Destination array contents: ");
  for(index=0;index<size;index++)
  {
     printf("%d ",ptr_array[index]);
  }
}

int main()
{
   int array[ARRAY_SIZE]={1,2,3,4,5};
   function(array,ARRAY_SIZE);
   printf("\n");
   return 0;
}

I did realize that the function accepting the argument can also follow as void function(int ptr_array[],int size) (or) void function(int ptr_array[5],int size).In this scenario the arguement passed is a int * but received in int []. So the questions are

  • It looks to me that compiler must do a cast of the accepted argument in the function.How does the array index impacts on the cast?
  • If it was a 2D array’s base address that is passed to the function, what is the correct type for accepting the arguments in int[][] form
  • 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-06-12T22:15:27+00:00Added an answer on June 12, 2026 at 10:15 pm

    In the context of a function parameter declaration, T a[] and T a[N] are synonymous with T *a; a is a pointer type, not an array type, regardless of whether you use [] or [N] or *.

    Chapter and verse:

    6.7.6.3 Function declarators (including prototypes)

    …
    7 A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to
    type’’, where the type qualifiers (if any) are those specified within the [ and ] of the
    array type derivation. If the keyword static also appears within the [ and ] of the
    array type derivation, then for each call to the function, the value of the corresponding
    actual argument shall provide access to the first element of an array with at least as many
    elements as specified by the size expression.

    Why would that be the case? This is why:

    6.3.2.1 Lvalues, arrays, and function designators

    …
    3 Except when it is the operand of the sizeof operator, the _Alignof operator, or the
    unary & operator, or is a string literal used to initialize an array, an expression that has
    type ‘‘array of type’’ is converted to an expression with type ‘‘pointer to type’’ that points
    to the initial element of the array object and is not an lvalue. If the array object has
    register storage class, the behavior is undefined.

    In the call to function, the expression array has type “5-element array of int“; by the rule in 6.3.2.1/3, it is converted (“decays”) to an expression of type “pointer to int“, and its value is the address of the first element (&array[0]); this pointer value is what gets passed to function.

    If array had been declared as int array[5][5], then the expression array would be converted from “5-element array of 5-element array of int” to “pointer to 5-element array of int“, or int (*)[5], and your function declaration would look like

    void function(int (*array)[5], int size)
    

    which could also be written as

    void function(int array[][5], int size)
    

    or

    void function(int array[5][5], int size)
    

    Note that in this case, the size of the outer dimension is not optional; it must be specified so that the compiler knows the size of the type being pointed to.

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

Sidebar

Related Questions

As it is clear from question, if I convert a normal method to static
What is the normal behavior in Objective-C if you call a method on an
Generating normal columnar data in excel file is quite easy but does any one
In attempting to use scipy's quad method to integrate a gaussian (lets say there's
Normal way: class A: def __init__(self): self.a.b.c = 10 def another_method(self): self.a.b.c = self.a.b.c
Normal Display (Xcode 4.2 4D199, Mac OS X Lion): Abnormal Display (Xcode 4.2 4C199,
The normal JSON approach looks something like this: { list: [ { header1: some
In normal mode I can hit Ctrl + E which deletes the rest of
For normal (say Windows Forms) C# applications, to execute commands after a successful build
A normal UserControl looks like this in XAML: <UserControl x:Class=mynamespace.foo ...namespaces...> <!-- content -->

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.