Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void pointerNonsense() {
- int a[] = {4, 5, 6};
- printf( "%p\n\n", a ); // Verify that a is a pointer
- for ( int i = 0; i < 3; i++ ) {
- printf( "Element %d\n", i );
- // All will print the value of i
- printf( "%d\n", *( a + i ) );
- printf( "%d\n", *( i + a ) );
- printf( "%d\n", a[i] );
- printf( "%d\n", i[a] );
- printf( "%d\n", ( a + i )[0] );
- printf( "%d\n\n", 0[ a + i ] );
- }
- printf( "This will also run:\n" );
- int b = 123;
- int *ptr = &b;
- // All will print 123
- printf( "%d\n", b );
- printf( "%d\n", *&b );
- printf( "%d\n", *ptr );
- printf( "%d\n", ptr[0] );
- printf( "%d\n", 0[ptr] );
- printf( "%d\n", (&b)[0] );
- printf( "%d\n", 0[&b] );
- }
- int main() {
- pointerNonsense();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement