C - Convert array of elements into 2-d matrix

C - Convert array of elements into 2-d matrix

It might be a stupid question, but I wonder if there is a efficient way to do this.

It might be a stupid question, but I wonder if there is a efficient way to do this.

The situation:

int* array = malloc(n * m * sizeof(int));
//want to convert array into M[n][m]

what I am doing now:

int** M = malloc(n * sizeof(int*));
for(int i = 0; i < n; i++, array += m)
  M[i] = array; 

I don't think the conversion should be this complex. Is there any simple syntax C provided? Can I declare an extern M[n][m] then set its address to the array?

(error handling and memory management in the sample is omitted for simplicity. Just think it as a part of some function.)

c arrays

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C++ Arrays And Multidimensional Arrays

In this article we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

C++ Arrays And Multidimensional Arrays

In this video we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

Anonymous array in C#| Anonymous Collection | C# Bangla Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Anonymous Array in C#. Blog : http://aspdotnetexplorer.blogspot.com Like our page...

Count of triplets (a, b, c) in the Array such that a divides b and b divides c

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

Loops in C++ | For, While, and Do While Loops in C++

In this Video We are going to see how to use Loops in C++. We will see How to use For, While, and Do While Loops in C++.