Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
664 B
3
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int* reserveAndInitializeBlock()
{
    int* block = ( int* )malloc( 4 * sizeof( int ) );

    if( block != NULL )
    {
        *( block ) = 5;
        *( block + 1 ) = 2;
        *( block + 2 ) = -3;
        *( block + 3 ) = -5;
    }

    return block + 3;
}

int main()
{
    int* lastVariable = reserveAndInitializeBlock();

    if( lastVariable != NULL )
    {
        printf( "Wartosci zmiennych w bloku: \n%d\n%d\n%d\n%d\n",
                *( lastVariable ), *( lastVariable - 1 ), *( lastVariable - 2 ), *( lastVariable - 3 ) );
    }

    free( lastVariable - 3 );

    return 0;
}
Leave a Comment