1 2 3 4 5

  • The only difference between arrays and pointers is that
    declaring aas an array means that the identifier
    ais read-
    only
    . That is, it cannot appear as an Lvalue.

pa= &a[3]
a= pa + 1

is ok
is not

Here we are incrementing pa by one unit of size float.
This is an address, but if we store it in a, then we would be
saying that
&a[0]is now &a[1].Even a computer would be
confused!! Therefore not allowed, because the original
array declaration was


float a[10];


Dynamic Memory Allocation.

By using the three routines below we can implement
dynamically allocated arrays by providing a mechanism for
obtaining a pointer to a block of new memory.


#include <stdio.h>


void* malloc( size_t size );


void* calloc( size_t NumMembers, size_t size );


void free( void* p );


Look at the examples pointers-3.c and its associated output
pointers-3.log

January 26, 1998

Page5

JH/TM

[CONVERTED BY MYRMIDON]