Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //:==========================================================://
- //: ://
- //: www.twitch.com/KanjiCoder ://
- //: ://
- //: #_MAKE_SURE_I_UNDERSTAND_POINTERS_# ://
- //: ://
- //: Every once and a while I do some weird stuff with ://
- //: pointers and I end up having the thought... ://
- //: ://
- //: "I thought I knew pointers. But maybe I don't." ://
- //: ://
- //: This code was written after one of those moments. ://
- //: To hopefully solidify my mental model of pointers. ://
- //: ://
- //: Maybe the "elaborative encoding" of thinking of ://
- //: arrays and the values they store as a big crane ://
- //: arm that selects shoes (values) by moving to ://
- //: different locations (boxes) will help someone ://
- //: besides myself. ://
- //: ://
- //:==========================================================://
- #include <stdint.h>
- #include <stdio.h>
- #define VOD void
- #define I32 int32_t
- #define P_F printf
- //:------------------------------------------------------://
- //: ://
- //: ://
- //: ://
- //: ================================================== ://
- //: Crane Arm Track ////////////////////////////////// ://
- //: ================================================== ://
- //: | | ://
- //: arr[ 1 ] &( arr[ 3 ] ) ://
- //: | | ://
- //: +----+----+ +----+----+ ://
- //: | | | | ://
- //: | | V V ://
- //: [ 0 ]| 1 |[ 2 ][ 3 ] <--Boxes
- //: V V ://
- //: [ B B B B ][ B B B B ][ B B B B ][ B B B B ] <--Shoes
- //: ^ ^ ://
- //: | | ://
- //: +----+----+ ://
- //: | ://
- //: 32Bit_Value ://
- //: ( Shoe ) ://
- //: ://
- //:------------------------------------------------------://
- VOD set_dex(
- I32 *crane_arm_airspace_position
- ){
- //: "*" pluges crane arm down Inserts Value ://
- //: | | ://
- //: +-------------+--------------+ +--+--+ ://
- //: | | | | ://
- //: V V V V ://
- (*crane_arm_airspace_position) = ( 666 );
- }
- I32 main( VOD ){
- I32 eve , odd , dex ;
- I32 arr[ 10 ]={ 0 };
- for( dex = 0 ; dex <= 9 ; dex++ ){
- eve =( 0 == ( dex % 2 ) );
- odd =( 1 == ( dex % 2 ) );
- if( eve ){ arr[ dex ]=( 333 ); };
- if( odd ){ set_dex( &( arr[ dex ] ) ); };
- };;
- for( dex = 0 ; dex <= 9 ; dex ++ ){
- P_F( "(%d):(%d)\n" , dex , arr[ dex ] );
- /** **************************************** ***
- *** expected output : ***
- *** ***
- *** (0):(333) ***
- *** (1):(666) ***
- *** (2):(333) ***
- *** (3):(666) ***
- *** (4):(333) ***
- *** (5):(666) ***
- *** (6):(333) ***
- *** (7):(666) ***
- *** (8):(333) ***
- *** (9):(666) ***
- *** ***
- *** **************************************** **/
- };;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement