matrix pointer c
#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;
}/*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;arr[i][j] = *(ptr + (i x no_of_cols + j))
1 2 3 4 5 6 7 8 9 10 11 12
Also in C:
- concatenate two strings in c
- c \a
- c bool
- unable to locate package dos2unix
- code: 'EADDRINUSE', [0] errno: 'EADDRINUSE', [0] syscall: 'listen', [0] address: '::', [0] port: 5000
- modulation
- simpy process return value
- c check if char is number
- what is strikethrough in markdown
- keras conv2d batchnorm
- coin row problem in linear time
- c program to find number of days in a month using switch case
- RuntimeError: You must setup() the GPIO channel first
- amazon kinesis disaster recovery
- get the latest field in mongodb collection
- how to pass an array to a thread in c?
- rakshabandhan 2020
- pebble scripting Boolean expression
- strtoul C
- fscanf stops at space
- macos prevent disk mounting
- how to add to the end of a linked list
- arduino knn
- c if int