Pointers and array

i have doubt that suppose a[10] is an array we get the 6 element of this array by *(a+6) but in the 2 d array if we print ((a+2)) this gives the value.

@Ashish2001 what do you want to say ? explain with a example

i want to say if we are using 1d array to get any element of the array we just type 1* but in 2d array if we use * 1 time we do not get it insted we get the address

@Ashish2001 yes thats because there is difference in both 1d array has only a row while 2d consists of multiple rows so using 1* + something on both will give diff things

i have another doubt what is the difference between *ptr[] and (*ptr)[];

@Ashish2001 here see this it will resolve your doubt
https://stackoverflow.com/questions/13910749/difference-between-ptr10-and-ptr10#:~:text=In%20the%20printf("%d,0]%20which%20value%20is%200.&text=int%20(*p)[10]%20means%20that%20p%20is%20now,array%20of%2010%20integer%20pointers%20.

#include using namespace std; int main() { int arr[] = { 3, 5, 6, 7, 9 }; int *p = arr; int (*ptr)[5] = &arr; cout << "p = “<< p <<”, ptr = " << ptr << endl; cout << "*p = “<< *p <<”, *ptr = " << *ptr << endl; cout << "sizeof§ = "<< sizeof§ << ", sizeof(*p) = " << sizeof(*p) << endl; cout << "sizeof(ptr) = "<< sizeof(ptr) << ", sizeof(*ptr) = " << sizeof(*ptr) << endl; return 0; }

why ptr and *ptr is giving the same output

@Ashish2001 please provide the code using cb ide link with indentation its very difficult to read like this

#include <bits/stdc++.h>

using namespace std;

int main()

{

int arr[] = { 3, 5, 6, 7, 9 };

int *p = arr;

int (*ptr)[5] = &arr;

cout << "p = " << p << ", ptr = " << ptr << endl;

cout << "*p = " << *p << ", *ptr = " << *ptr << endl;

cout << "sizeof(p) = " << sizeof (p) <<

", sizeof(*p) = " << sizeof (*p) << endl;

cout << "sizeof(ptr) = " << sizeof (ptr) <<

", sizeof(*ptr) = " << sizeof (*ptr) << endl;

return 0;

}
now ok?

i didn’t get any reply yet

?
shall i repeat the question again

@Ashish2001 sorry was busy with something let me check

@Ashish2001 you have to do **ptr to give o/p 3 as *ptr as the address of array
(*ptr)[5] is pointer to array which have address of it so *ptr gives address and **ptr value
is it ok bro??