how to declare 2 d array using malloc
C
#include <stdio.h>
#include <stdlib.h>
int main()
{
int r = 3, c = 4;
int *arr = (int *)malloc(r * c * sizeof(int));
int i, j, count = 0;
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
*(arr + i*c + j) = ++count;
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
printf("%d ", *(arr + i*c + j));
/* Code for further processing and free the
dynamically allocated memory */
return 0;
}
Also in C:
- Title
- how to change the mapping from jkil to wasd in vim
- Category
- C
- Title
- scanf read line
- Category
- C
- Title
- stack implementation
- Category
- C
- Title
- es palindromo
- Category
- C
- Title
- c struct
- Category
- C
- Title
- command line arguments c
- Category
- C
- Title
- write a binary file c
- Category
- C
- Title
- mitch mcconnell
- Category
- C
- Title
- error 403
- Category
- C
- Title
- install postgres on linux
- Category
- C
- Title
- unordered_map
- Category
- C
- Title
- xamarin command listview button
- Category
- C
- Title
- ModuleNotFoundError: No module named 'easydict'
- Category
- C
- Title
- version of libgcc
- Category
- C
- Title
- chat
- Category
- C
- Title
- battlefield4u.com
- Category
- C
- Title
- uninstall elgg from hostgtor
- Category
- C
- Title
- c print array
- Category
- C
- Title
- tar cmd
- Category
- C
- Title
- Print the number 0 using write()
- Category
- C
- Title
- how to login to another user in powershell
- Category
- C
- Title
- remove element queue
- Category
- C
- Title
- Declare macro
- Category
- C
- Title
- hello world
- Category
- C
- Title
- How to setup a line length marker in vim
- Category
- C
- Title
- error: dereferencing pointer to incomplete type
- Category
- C
- Title
- append to list in c
- Category
- C
- Title
- c allocate array
- Category
- C
- Title
- powershell list big files
- Category
- C
- Title
- boolean function c
- Category
- C
- Title
- check if string in string c
- Category
- C
- Title
- xmlns='' was not expected
- Category
- C
- Title
- how to make a linked list in c
- Category
- C
- Title
- time now c
- Category
- C
- Title
- hopw to check how many duplicates in an array c
- Category
- C
- Title
- c vs python
- Category
- C
- Title
- switch case c
- Category
- C
- Title
- PS1 modified lags
- Category
- C
- Title
- what is the meaningof noremap
- Category
- C
- Title
- atoi
- Category
- C
- Title
- c check if array is empty
- Category
- C
- Title
- java.lang.SecurityException: Permission denied (missing INTERNET permission?)
- Category
- C
- Title
- how to do Employing defensive code in the UI to ensure that the current frame is the most top level window
- Category
- C
- Title
- random en c
- Category
- C
- Title
- disable gnu++11 option
- Category
- C
- Title
- how to pass an array to a thread in c?
- Category
- C
- Title
- strcat in c
- Category
- C
- Title
- printf in c
- Category
- C
- Title
- fa fa-facebook
- Category
- C
- Title
- how to use a pointer as a parameter in c
- Category
- C
- Title
- vbl share price
- Category
- C
- Title
- c bit access struct
- Category
- C
- Title
- arduino knn
- Category
- C
- Title
- what is x:Name Xamarin forms
- Category
- C
- Title
- how to check the size of a file c
- Category
- C
- Title
- find string in all files powershell
- Category
- C
- Title
- update ubuntu in terminal
- Category
- C
- Title
- c array
- Category
- C
- Title
- how to open a website in c
- Category
- C
- Title
- triangulo
- Category
- C
- Title
- code wars responsable drinker
- Category
- C
- Title
- convert string to float c
- Category
- C
- Title
- delete docker image repository none
- Category
- C
- Title
- what is conio.h
- Category
- C
- Title
- c if int
- Category
- C
- Title
- how to put a struct in another struct C
- Category
- C
- Title
- typedef in c
- Category
- C
- Title
- division recursiva
- Category
- C
- Title
- matrix c declaration
- Category
- C
- Title
- read a binary file c
- Category
- C
- Title
- accessing elements 2D array using pointers
- Category
- C
- Title
- '&&' within '||'
- Category
- C
- Title
- jock cranley
- Category
- C
- Title
- How to pull images from Docker Registry
- Category
- C
- Title
- pangram program in c
- Category
- C
- Title
- CL/cl.h: No such file or directory
- Category
- C
- Title
- c string concatenation with int
- Category
- C
- Title
- how to open chrome using cmd
- Category
- C
- Title
- first person view unity
- Category
- C
- Title
- simpy process return value
- Category
- C
- Title
- printf n characters c
- Category
- C
- Title
- css selector for sibling element
- Category
- C
- Title
- Docker error Error response from daemon: conflict: unable to remove repository reference
- Category
- C
- Title
- csrf_exempt
- Category
- C
- Title
- ModuleNotFoundError: No module named 'cv2'
- Category
- C
- Title
- what is stdin in c
- Category
- C
- Title
- powershell search big files
- Category
- C
- Title
- enum c
- Category
- C
- Title
- XAudio2 C
- Category
- C
- Title
- strtok
- Category
- C
- Title
- what are the causes of memory leaks in c
- Category
- C
- Title
- download file by command line windows
- Category
- C
- Title
- how to get random numbers in c
- Category
- C
- Title
- how to print a file c
- Category
- C
- Title
- maximo comun divisor
- Category
- C
- Title
- tmux how to kill all sessions
- Category
- C
- Title
- stack
- Category
- C
- Title
- docker images command
- Category
- C
- Title
- slug urls django
- Category
- C
- Title
- c check if char is number
- Category
- C