Search
 
SCRIPT & CODE EXAMPLE
 

C

Access 2d array with pointer C

#include <stdio.h>

int main(void) {
  
  // 2d array
  int num[3][4] = {
    {1, 2,  3,  4},
    {5, 6,  7,  8},
    {9, 10, 11, 12}
  };
  
  int
    ROWS = 3,
    COLS = 4,
    i, j;

  // pointer
  int *ptr = &num[0][0];
  
  // print the element of the array via pointer ptr
  for (i = 0; i < ROWS; i++) {
    for (j = 0; j < COLS; j++) {
      printf("%d ", *(ptr + i * COLS + j));
    }
    printf("
");
  }
  
  return 0;
}
Comment

Access 2d array with pointer C

arr[i][j] = *(ptr + (i x no_of_cols + j))
Comment

PREVIOUS NEXT
Code Example
C :: user define function in c 
C :: print only last 3 number float in c 
C :: getline() in c 
C :: c list 
C :: how to join an array of strings c 
C :: getline function in c 
C :: redis service 
C :: virtualbox how to move vmdk to another folder 
C :: open a file in from terminal 
C :: commenting in c 
C :: declaration of string in c 
C :: realloc in c 
C :: *= in c 
C :: c code recursive function to print numbers between two numbers 
C :: Number 10 
C :: c code to mips assembly converter online 
C :: c program boilerplate 
C :: anthracnose pronounce 
C :: convert calendar time to epoch in c programming 
C :: nested if example in c 
C :: perl file handling 
C :: c pointers to struct 
C :: pre-commit configuration 
C :: data breach 
C :: reverse string in c 
C :: yt-project annotate_scale 
C :: C fgets() and puts() 
C :: arma 3 nearest terrain objects 
C :: formula to find the area of a trapezium in c 
C :: recursion c prime number 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =