cplusplus:c_vs._c
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
cplusplus:c_vs._c [2016/04/21 23:09] – [Dynamic memory] mithat | cplusplus:c_vs._c [2016/04/21 23:35] – [Structs] mithat | ||
---|---|---|---|
Line 76: | Line 76: | ||
* Best practice to use them anyway. | * Best practice to use them anyway. | ||
- | ===== Named constants | + | ===== Named constants |
* '' | * '' | ||
- | * ''# | + | * ''# |
- | * ''# | + | |
- | <code c> | + | |
#define PI 3.1415 | #define PI 3.1415 | ||
#define TAX_RATE 0.065 | #define TAX_RATE 0.065 | ||
+ | </ | ||
+ | * ''# | ||
#define square(x) ((x) * (x)) | #define square(x) ((x) * (x)) | ||
</ | </ | ||
- | ===== Dynamic memory ===== | + | ===== Dynamic memory |
- | * Allocating/ | + | * Allocating memory:<code c> |
- | <code c> | + | int *x = malloc(sizeof(int)); |
- | int *x = malloc(sizeof(int)); | + | int *xArry = malloc(sizeof(int) * 10); /* allocate array of ints */ |
- | int *x_array | + | |
- | + | ||
- | /* release storage that was allocated */ | + | |
- | free( x ); | + | |
- | free( x_array ); | + | |
</ | </ | ||
+ | * Deallocating memory:< | ||
+ | free(x); | ||
+ | free(xArry); | ||
+ | </ | ||
===== Structs ===== | ===== Structs ===== | ||
- | * Need to use '' | + | * You must use the '' |
- | <code c> | + | |
struct MyStruct | struct MyStruct | ||
{ | { |
cplusplus/c_vs._c.txt · Last modified: 2016/04/22 01:10 by mithat