You are on page 1of 3
C and C++ Cheat Sheet libraries ffinclude input and output functions ffinclude string related functions include memory allocation, rand, and other functions include math functions include time related functions functions returnType functonNeme( inptTType inputIName, inpu2Type input2Name, ..) - 1 something fet valu 1! value must bo of type reurnType ) comments 1 one line comments this is @ C++ style one line comment mutiple line this is @ traditional © style comment block comment */ variable types char holds @ character, or @ number from -128 to 127 (1 byte) boo! holds @ boolean value, either true or false (1 byte) int hold an integer (a positive or negative number with NO decimal, 4 bytes) float holds real number (a positive or negative number with a decimal, 4 bytes) void no type, raw binary data conditionals WA fs equ © 8, ths Is tu; ohenise, foe if A is NOT equal to B, this is tuer ofenise, ifs false iA is less thon B, ts i tue; otherwise, ts talse if A is gretor B, ia tue; ctervion, flea iA is bos en or equal to ©, ths ie bus; conve, te flso iF A ts gretor ov equal to By is bx ive; erwice, Kf control flow pe>rr> if ( conditional ) if ( conditional ) it ( conditional ) { { { 1 do something 1 do something 1 do. something ) } ! else flse if ( another conditional ) 4 { 1 do something else 1 do something else ) ) else { 1 do something as defauit ) while while ( conditional ) placing “break;” inside @ while loop { breaks out of the loop do something placing “continue;” inside a while } loop jump for for | initialization; test; command ) “break,” and ‘continue;* can be this is equivalent to: | used within for loops as well with initialization; H do something identical effects while( test ) i { i do something command } switch swith (vale ) tis i equvalet tx: { if ( variable == valuet ) cave vobet ( 1 8 someting 1 do someting brea ) case value?: else if ( variable = value? ) 1 8 someting ese ( bras 1 do someting ose dest ) 11 60 someting by dtout ese bra ( ) 1 do someting by default in printf formats ‘kd: integer Bf: float oF double ‘ks: sting (char array) ‘ke: char (single character) scanf formats %d: integer %f: float %Glt: double (fist character is L, not one!) %s: sting (char array) %e: char (single character) string methods FT to use these methods, you must include *) stepy(char dest], char ste) copies src into dest int stlen(char s[) retums length of s int stromp(char st, char 82) retums negative if st < $2, 0 if st = 82 positve if st > 52 sticat(char dest, char ste) adds src to the end of dest abstract classes and methods virtual void sound{char sl) = 0; | Reminder: no “abstract” Keyword. | Class headers do not indicate | whether the class is abstract or not. A class is abstract if it | contains any abstract methods. if else if () { statement 1>; ) else ( ; } data types in, char, float, double, void, bool logical operators Il (logical OR), && (logical AND), ! (logical NOT) arithmetic operators + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus) relational operators < (ess than), <= (less than or equal to}, > (greater than), >= ( greater than or equal to), == (equal to), = (not equal to)

You might also like