Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C++ 1 Page Cheat

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

C++ References Sheet Cheat Sheet

by vittochan (vittochan) via cheatography.com/26692/cs/36424/

Include Headers Pointers If Else

#include <headername> int *ptr; Pointer definition if (condition) {


#include <iostream> Several standard ptr = &var1; ptr set to address of var1 ​ ​ ​ \\Do something
stream objects }
var2 = *ptr; set var2 to value of var1
if (condition) {
#include <string> std::b​asi​c_s​tring
​ ​ ​ \\Do something
class template Arithmetic Operators
} else {
#include <math> Behaves as if each +, - , *, / Addition, subtra​ction, multip​‐ ​ ​ ​ \\Do something
name from <cm​ath> lic​ation, division }
is placed in global
% Modulus (rest of division) if (condition) {
namespace, except
++ Add 1 to variable ​ ​ ​ \\Do something
for names of
(example: i++) } elsei f (condition) {
mathem​atical
​ ​ ​ \\Do something
special functions -- Subtract 1 to variable
} else {
(example: i--)
#include <fstream> std::b​asi​c_f​stream, ​ ​ ​ \\Do something
std::b​asi​c_i​fst​ream, +=, -=, *= , /= Add/su​btr​act​/mu​lti​ply​/divide }
std::b​asi​c_o​fstream a value from the variable
condition must be a condition that return a
class templates and (example: i+=2; is equal to
boolean value true or false
several typedefs i=i+2;)

#include <cctype> Behaves as if each Switch


name from <cc​typ​e> Relational Operators
switch (variable) {
is placed in global < Less than
case constant1 :
namespace <= Less or Equal than ​ ​ ​ \\Do something
> Greater than break;
Namespace
>= Greater or Equal than case constant2 :
using namespace std; ​ ​ ​ \\Do something
== Equal than
break;
Data Types != Not Equal than
default:
int integer type (-32768 to 32767) ​ ​ ​ \\Do something
Logical Operators
break;
char single character type
|| OR }
float Floati​ng-​point types (single
&& AND default is optional
precision)
! NOT
double Floati​ng-​point types (double
precision)
bool true or false
void type with an empty set of values

Comments

//Single line
/*Multiple
lines*/

By vittochan (vittochan) Published 8th January, 2023. Sponsored by ApolloPad.com


cheatography.com/vittochan/ Last updated 8th January, 2023. Everyone has a novel in them. Finish
Page 1 of 2. Yours!
https://apollopad.com
C++ References Sheet Cheat Sheet
by vittochan (vittochan) via cheatography.com/26692/cs/36424/

While Loop

while (condition) {
​ ​ ​ \\Do something
}

Loop as long as the condition is true, when


it becomes false it exits

Do-While Loop

do {
​ ​ ​ \\Do something
} while (condition);

Loop as long as the condition is true, when


it becomes false it exits

For Loop

for (initialize; condition; update ) {


​ ​ ​ \\Do something
}
example:
for (int i=0; i<10; i++) {
​ ​ ​ \\Do something
}

Loop as long as the condition is true, when


it becomes false it exits

By vittochan (vittochan) Published 8th January, 2023. Sponsored by ApolloPad.com


cheatography.com/vittochan/ Last updated 8th January, 2023. Everyone has a novel in them. Finish
Page 2 of 2. Yours!
https://apollopad.com

You might also like