-1

I'm not sure how to call this two pointer differently so please correct my terms.

#include <stdio.h>

int main()
{
    int arr[3]={10,20,30};
    int * ptr = &arr[0];// arr

    return 0;
}

is there some differences between arr and *ptr? Both pointed at the same address, but what's the difference.

Julian Declercq
  • 1,536
  • 3
  • 17
  • 32

2 Answers2

1

arr is an array and ptr is a pointer of type int.

There are differences . Let me list few

  1. sizeof(arr) is different from sizeof(ptr)
  2. You can do ptr++ pointer operation using ptr whereas arr++ is an invalid operation.

Going by your comment of what is the difference between pointer and array I have answered your question

int a = 10;
int b[5] = {1,2,3,45};
int *p = &a;
b = &a;  /* not valid */

b is a array and not a pointer so it can't hold address of a variable.

p = b;
p = p +1;

printf("%d\n",*p); /* valid as p is pointing to second element in the array */

b = b+1;

is not valid because array can't be a modifiable lvalue

Gopi
  • 19,784
  • 4
  • 24
  • 36
-1

'is there some differences between arr and *ptr'

Yes, there is. For example sizeof(*ptr) is a size of int value, that is sizeof(int), while sizeof(arr) is a size of the whole array and equals 3*sizeof(int).

CiaPan
  • 9,381
  • 2
  • 21
  • 35