top of page

[C] Pass a pointer to a 2D array as a function argument

What want to do

  • There is an operation that operates on two-dimensional arrays

  • There are multiple targets to be processed


In this case, I want to make this process into a function, but I'm not sure how to define the arguments.



Solution

Suppose the array size is fixed, you can do it like this:

// Define a typedef for the array type
typedef int myArray[2][3];

// Function to operate on a 2x3 array
void f(myArray arr) {
    ...
}

Use it like this:

int main() {
    myArray x = {{1, 2, 3}, {4, 5, 6}}; // Define array x
    myArray y = {{7, 8, 9}, {10, 11, 12}}; // Define array y

    // Pass array x to function f
    f(x);

    // Pass array y to function f
    f(y);

Recent Posts

See All

[C] Array of function pointers

What want to do As stated in the title, I would like to define an array of function pointers. Specifically, for example, the third...

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page