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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:05:00+00:00 2026-06-12T21:05:00+00:00

Say I have an array: array[2][4] , and inside the main method, I have

  • 0

Say I have an array: array[2][4], and inside the main method, I have a call to a function blackandwhite. How can I pass this method the length and width of the array as arguments?

  • 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-12T21:05:03+00:00Added an answer on June 12, 2026 at 9:05 pm

    This is a possible solution :

    void blackandwhite(int* array, int height, int width)
    {
        // Array-processing done here.
        // array is pointer to int,
        // initially points to element myarray[0][0].
        // variable height = 2;
        // variable width = 4;
    
    }
    
    
    int main()
    {
        int myarray[2][4];
        blackandwhite(&myarray[0][0], 2, 4);
    }
    

    One can find the size of an array i.e. the number of elements in it by the following construct :

    int array[8];
    int size = sizeof(array)/sizeof(array[0]);
    

    Unfortunately, C arrays are native arrays and do NOT contain any metadata embedded in them. Rows and Columns are just a way of representing/accessing what is essentially linear storage space in memory. AFAIK, there is no way to automatically determine the number of rows/columns of a 2D-array, given a pointer to it (in C).

    Hence one needs to pass the number of columns/rows as separate arguments along-with the pointer to the 2D-array as shown in the example above.

    More info on a related question here.


    UPDATE:

    Common pitfall no.1 : Using int** array in param-list
    Note that a pointer to a 2 dimensional array of integers is still a pointer to a int.
    int** implies that the param refers to a pointer to a pointer to an int, which is NOT the case here.

    Common pitfall no.2 : Using int[][] in param-list
    Failing to pass the dimension(s) of the array. One need NOT pass the size of the array’s 1st dimension (but you may but the compiler will ignore it). The trailing dimensions are compulsory though. So,

    // is INVALID!
    void blackandwhite(int array[][], int height, int width)
    
    // is VALID, 2 is ignored.
    void blackandwhite(int array[2][4], int height, int width)
    
    // is VALID.
    void blackandwhite(int array[][4], int height, int width)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have an array, data, of unknown length. Is there a shorter method
Let's say I have a JavaScript object: function a(){ var A = []; this.length
So, lets say in my main activity, i have an array declared like this,
Say I have an array like this: [white, red, blue, red, white, green, red,
Let's say I have a NSArray with 50-100 objects inside. How can I put
I have a array of string say: String[] Fields=new String[]{RowField,RowField1} In which I can
Say I have a simple PHP loop like this one // Bad example $array
say I have an array of objects with html strings inside (there are other
Let's say we have an array of PRINTER_INFO_2 like this: PRINTER_INFO_2* printers = (PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)
let's say I have this string array in java String[] test = {"hahaha lol",

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.