Int *ptr = &x; and int*ptr = arr; in case of array why not int *ptr = &arr;

int ptr = &x; and intptr = arr; in case of array why not int *ptr = &arr;

#include using namespace std; int main() { int a=10, *j; void *k; j=k=&a; j++; k++; cout<<j<<k; return 0;} how is this leaking memory

The name of array i.e. arr is a pointer to the memory address of the first element of array (arr[0])
cout<<arr; // address of arr[0]
cout<<arr; // first element of array i.e. arr[0]
cout<<
(arr+1); //second element of array.

Therefore, we write “int *ptr = arr” becaure arr itself refers to the address of first index of array.

There is a correction in your code.

#include
using namespace std;
int main()
{
int a=10, j;
void k;
j=&a; // you were performing invalid conversion from 'void
’ to 'int

k=&a;
j++;
k++;
cout<<j<<k;
return 0;
}