Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> //: for: printf(...)
- #include <stdlib.h> //: for: malloc(...)
- struct MyStruct{
- int a;
- int b;
- };
- int main( void ){
- //:Allocated On The Stack:
- struct MyStruct my_struct_001;
- //:Allocate On The Heap:
- struct MyStruct* my_struct_002=(
- malloc( sizeof( struct MyStruct ) )
- );;
- //:Allocate On The Heap:
- //:The way people say you should do it in case the
- //:variable's underlying type changes in the future.
- //:(I think this way is stupid as hell.)
- struct MyStruct* my_struct_003 =((void*)0);
- my_struct_003=(
- malloc( sizeof( my_struct_003 ) )
- );;
- my_struct_001.a = 10;
- my_struct_001.b = 11;
- my_struct_002 -> a = 20;
- my_struct_002 -> b = 21;
- my_struct_003 -> a = 30;
- my_struct_003 -> b = 31;
- printf( "[my_struct_001.a]:%d\n" , my_struct_001.a );
- printf( "[my_struct_001.b]:%d\n" , my_struct_001.b );
- printf( "[my_struct_002->a]:%d\n" , my_struct_002->a );
- printf( "[my_struct_002->b]:%d\n" , my_struct_002->b );
- printf( "[my_struct_003->a]:%d\n" , my_struct_003->a );
- printf( "[my_struct_003->b]:%d\n" , my_struct_003->b );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement