cplusplus:c_versus_cplusplus
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cplusplus:c_versus_cplusplus [2020/05/04 01:23] – [Strings] mithat | cplusplus:c_versus_cplusplus [2020/05/04 01:40] (current) – [C Examples] mithat | ||
---|---|---|---|
Line 73: | Line 73: | ||
* C's '' | * C's '' | ||
===== Defining variables ===== | ===== Defining variables ===== | ||
- | * In older versions of C, you //must// define variables at the beginning of a function. | ||
- | * Common practice today anyway. | ||
<code c> | <code c> | ||
int main( ) | int main( ) | ||
Line 80: | Line 78: | ||
int a,b,c; | int a,b,c; | ||
float x,y,z; | float x,y,z; | ||
+ | | ||
... | ... | ||
+ | } | ||
</ | </ | ||
- | + | | |
+ | * Common practice today anyway. | ||
===== Prototypes ===== | ===== Prototypes ===== | ||
- | * Function prototypes are not required. | ||
- | * Best practice to use them anyway. | ||
<code c> | <code c> | ||
/* int foo(); < | /* int foo(); < | ||
Line 102: | Line 100: | ||
</ | </ | ||
+ | * Function prototypes are not required. | ||
+ | * Best practice to use them anyway. | ||
===== Named constants and macros ===== | ===== Named constants and macros ===== | ||
- | * '' | + | * '' |
* ''# | * ''# | ||
#define PI 3.1415 | #define PI 3.1415 | ||
Line 114: | Line 113: | ||
===== Casting ===== | ===== Casting ===== | ||
- | * No '' | ||
- | * Place the type you want a value cast to inside parenthesis before the value. | ||
<code c> | <code c> | ||
int myInt = 42; | int myInt = 42; | ||
Line 122: | Line 119: | ||
myDouble = (double)myInt/ | myDouble = (double)myInt/ | ||
</ | </ | ||
+ | * Place the type you want a value cast to inside parenthesis before the value. | ||
+ | * No '' | ||
===== Dynamic memory ===== | ===== Dynamic memory ===== | ||
Line 137: | Line 136: | ||
===== Structs ===== | ===== Structs ===== | ||
- | * Only member variables are allowed. | ||
- | * No member functions. | ||
- | * Everything is public. | ||
- | * No access specifiers. | ||
- | * You must use the '' | ||
- | |||
<code c> | <code c> | ||
struct MyStruct | struct MyStruct | ||
Line 152: | Line 145: | ||
struct MyStruct aStructInstance; | struct MyStruct aStructInstance; | ||
</ | </ | ||
+ | * Only member variables are allowed. | ||
+ | * No member functions. | ||
+ | * Everything is public. | ||
+ | * No access specifiers. | ||
+ | * You must use the '' | ||
+ | |||
+ | |||
===== Classes ===== | ===== Classes ===== | ||
Line 157: | Line 157: | ||
===== Some C Resources ===== | ===== Some C Resources ===== | ||
- | * [[https:// | + | * [[https:// |
- | * A [[http:// | + | * [[C examples|C code examples]] |
- | ===== C Examples ===== | ||
- | * Look [[C examples|here]]. |
cplusplus/c_versus_cplusplus.txt · Last modified: 2020/05/04 01:40 by mithat