Array is a pointer in C? [duplicate]

6

I'm reading a book about pointers in C, but since I'm new to such a language, the concept of pointers is a bit complex, and when I read the following definition, I came up with the question of whether an array is a pointer .

  

Pointer Variables

     

The current size required is not too   we have a way of informing the compiler that we want to store   is an address.   Such a variable is called a pointer variable.

By definition then, arrays are pointers, right? In some places, if you say that the array drops to a pointer, would it be correct to say that too?

    
asked by anonymous 03.07.2017 / 15:18

2 answers

6

A pointer is a special type of variable that stores addresses.

If a p pointer stores the address of a i variable, we can say p points to i or p is i address. (In somewhat more abstract terms, it is said that p is a reference to the i variable.) If a p pointer has a value other than NULL in> then *p is the value of the object pointed to by p . (Do not confuse this use of * with the multiplication operator!) For example, if i is a variable and p is &i then say *p is the same as say i .

Let's look at the examples:

  • char exemplo[20]
  • char *exemplo[20]
  • What's the difference between the 2?

    In the first example there is an array with 20 char s. In the second it has an array with 20 pointer for char .

    Credits: bigown

        
    03.07.2017 / 15:30
    3

    Variables that are pointers have an asterisk in their declaration. Then the array will only be pointer if it is with that asterisk. Samples:

    With pointers:

    int *x;
    char *array[];
    float *peso;
    

    No pointers:

    int x;
    char array[];
    float peso;
    
        
    03.07.2017 / 15:24