Using Pointers to Print 2D Arrays

preview_player
Показать описание
C Programming: Using Pointers to Print Two-Dimensional Arrays in C Programming.
Topic discussed:
1) Row major order.
2) Column major order.
3) Printing two-dimensional arrays using pointers in C.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #Pointers #2DArrays #PointersInC
Рекомендации по теме
Комментарии
Автор

Literally u cleared all my confusion within 4 minutes. Clear explanation 👌

imMortAlDA
Автор

That's why C is the most beautiful language of all.

fidalgoverde
Автор

Happy Teacher's Day Sir, Thank you for being such a great teacher.

utkarshmalviya
Автор

Great
but maybe is not useful when we want to print array in row column format
it will print it in one row

qandos-nour
Автор

I have anomaly?
When we have *p pointer then it's value will be printed
And when we have simple p the address will be printed am I right??

taibohere
Автор

you are great sir!! very good explanation..

bimalmurali
Автор

I made some code similar to yours because the first one (merely following the code shown in the video) showed an error after compiling. So this is the modified one:

#include<stdio.h>
int main()
{
int rows, cols;
printf ("Enter row: ");
scanf ("%d", &rows);
printf ("Enter column: ");
scanf ("%d", &cols);

int arr[rows][cols];

printf ("Enter %d numbers:\n", rows*cols);

int i, j;

for (i=0; i<rows; i++)
{
for (j=0; j<cols; j++)
{
scanf ("%d", &arr[i][j]);
}
}


int *p;

printf ("Printing the numbers again: \n");
for (p = &arr[0][0]; p <= &arr[rows-1][cols-1]; p++) //p has the address of the first element
{

printf ("%d ", *p);
}

return 0;
}

marbles
Автор

Can someone please tell me what the time complexity is for the pointer based approach?
Is it O(n) or O(n^2)

Thank you

AbhishekV-tf
Автор

so in 2d arrays when we pass the 2d array as argument to a function, we pass the base address as well right?

carlossantamaria
Автор

I love this and because of new concepts like this, I am starting to love C as same as I love Python, which is the easiest programming language.

_cse_sanjaykarthicks
Автор

how are 2D arrays stored in c++??? row major or column major??

trueresources
Автор

anyone please !
int *ptr;
for(ptr=&a[0][0][0] ;
{
printf(" value is: %d", *ptr);
}
the value of ptr exceeds using this ( ptr<&a[arr][rows][cols]) condition why ?
in 2d array(2*2) or any other

ptr<&a[rows][cols] values of ptr go outside of array but not if <= used ;
what is the reason .

jagdeepsingh-tvty
Автор

In this case, we can't change the line after printing a row. Am I right?

nilanjankar
Автор

Can I access the array index number instead of value using a pointer? If yes, how?

MKSundaram
Автор

you have cleared my all confusions in just four minits, which I couldn't in 4 hours.

mostafalabib
Автор

Is This playlist includes data structures or not? ...

pranaylambat
Автор

Many of us have fallen during our journey ☠.

shinimasud
Автор

Sir how should i get the remaining video playlist of data structure? please tell me procedure.

akshayrathod
Автор

The address `&a[0][0]` points to a first element of the first row of the array. The row's type is `int[2]`. Therefore according C standard this program is undefined for anything because pointer arithmeticsis only allowed within a single array. `&a[0][0]+2` is fine for comparison while `&a[0][0]+3]` will invoke Undefined Behavior.

tomaszstanislawski
Автор

Ye tho bawal chizz h be.. system hil jaye 😂

mysterious