Answers for "matrix pointer c"

C
0

accessing elements 2D array using pointers

#include<stdio.h>
//accessing elements of 2D array using pointers
int main(void){

    int arr[4][4]={{1,2,3,4},{5,6,7,8},{9,0,1,2}};
    int *ptr = &arr;

    //accessing the elements of 2D array using ptr
    for(int i=0;i<3;i++){
            for(int j=0;j<4;j++)
            printf("%d ",*((ptr+i*4)+j)); //4 is the number of columns
            //*((ptr+i*4)+j) is similar to arr[i][j]
            printf("\n");
    }
    return 0;
}
Posted by: Guest on June-18-2020
0

matrix pointer c

/*any type*/ array2d[nRows][nCol];
// normal 2D array accessing
array2d[iRow][jCol] = value1;
bool b = array2d[iRow][jCol] == value1;
// accessing 2D array with pointers
*(*(array2d + iRow) + jCol) = value2;
b = *(*(array2d + iRow) + jCol) == value2;
Posted by: Guest on January-25-2021
0

use of pointer in multidimensional array

arr[i][j] = *(ptr + (i x no_of_cols + j))
Posted by: Guest on July-02-2020
-1

use of pointer in multidimensional array

1 2 3 4 5 6 7 8 9 10 11 12
Posted by: Guest on July-02-2020

Code answers related to "C"

Browse Popular Code Answers by Language