User Tools

Site Tools


cplusplus:c_versus_cplusplus

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
cplusplus:c_versus_cplusplus [2020/05/04 01:23] – [Defining variables] mithatcplusplus:c_versus_cplusplus [2020/05/04 01:40] – [Some C Resources] mithat
Line 78: Line 78:
     int a,b,c;     int a,b,c;
     float x,y,z;     float x,y,z;
 +    
     ...     ...
 +}
 </code> </code>
-  * In older versions of C, you //must// define variables at the beginning of a function.+  * In older versions of C, you must define all variables at the beginning of a function.
   * Common practice today anyway.   * Common practice today anyway.
 ===== Prototypes ===== ===== Prototypes =====
-  * Function prototypes are not required. 
-  * Best practice to use them anyway. 
 <code c> <code c>
 /* int foo(); <--optional */ /* int foo(); <--optional */
Line 100: Line 100:
 </code> </code>
  
 +  * Function prototypes are not required. 
 +  * Best practice to use them anyway.
 ===== Named constants and macros ===== ===== Named constants and macros =====
-  * ''const'' is available only in newer versions of C.+  * ''const'' modifier is available only in newer versions of C.
   * ''#define'' preprocessor directive typically used instead.<code c>   * ''#define'' preprocessor directive typically used instead.<code c>
 #define PI 3.1415 #define PI 3.1415
Line 112: Line 113:
  
 ===== Casting ===== ===== Casting =====
-  * No ''static_cast<>'', etc. 
-  * 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 120: Line 119:
 myDouble = (double)myInt/3;  /* cast myInt to a double */ myDouble = (double)myInt/3;  /* cast myInt to a double */
 </code> </code>
 +  * Place the type you want a value cast to inside parenthesis before the value.
 +  * No ''static_cast<>'', etc.
  
 ===== Dynamic memory ===== ===== Dynamic memory =====
Line 135: Line 136:
  
 ===== Structs ===== ===== Structs =====
-  * Only member variables are allowed. 
-    * No member functions. 
-  * Everything is public. 
-    * No access specifiers. 
-  * You must use the ''struct'' keyword when defining ''struct'' variables. 
- 
 <code c> <code c>
 struct MyStruct struct MyStruct
Line 150: Line 145:
 struct MyStruct aStructInstance;  /* requires struct keyword */ struct MyStruct aStructInstance;  /* requires struct keyword */
 </code> </code>
 +  * Only member variables are allowed.
 +    * No member functions.
 +  * Everything is public.
 +    * No access specifiers.
 +  * You must use the ''struct'' keyword when defining ''struct'' variables.
 +
 +
  
 ===== Classes ===== ===== Classes =====
Line 155: Line 157:
 ===== Some C Resources ===== ===== Some C Resources =====
  
-  * [[https://www.math.brown.edu/~jhs/ReferenceCards/CRefCard.v2.2.pdf|C Reference Card (ANSI)]] +  * [[https://www.math.brown.edu/~jhs/ReferenceCards/CRefCard.v2.2.pdf|C Reference Card (ANSI)]] Highly recommended! 
-  * [[http://www.tutorialspoint.com/cprogramming/|C Tutorial]] from Tutorials Point+  * [[C examples|C code examples]]
  
 ===== C Examples ===== ===== C Examples =====
   * Look [[C examples|here]].   * Look [[C examples|here]].
cplusplus/c_versus_cplusplus.txt · Last modified: 2020/05/04 01:40 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki