C++ Cheatsheet _ CodeWithHarry
C++ Cheatsheet _ CodeWithHarry
PM CodeWithHarry
C++ Cheatsheet
Haris Ali Khan
Basics
Basic syntax and functions from the C++ programming
language.
Boilerplate
##iinncclluuddee
<<iioossttrreeaamm>>
uussiinngg
nnaammeessppaaccee
std;
iinntt mmaaiinn() {
CCooddeeWWiitthhHHaarrrryy"";
rreettuurrnn 00 ;
}
cout <<
It prints output on the screen used with
the insertion operator
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 1/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
Data
types
The data type is the type of data
Character type
Typically a single octet(one byte). It is an
integer type
cchhaarr variable_name;
Integer type
The most natural size of integer for the
machine
iinntt variable_name;
Float type
A single-precision floating-point value
ffllooaatt variable_name;
Double type
A double-precision floating-point value
ddoouubbllee variable_name;
Void type
Represents the absence of the type
vvooiidd
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 2/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
bbooooll
Escape Sequences
It is a sequence of characters starting with a backslash, and it
doesn't represent itself when used inside string literal.
Alarm or Beep
It produces a beep sound
cout<<"" \\ aa "" ;
Backspace
It adds a backspace
cout<<"" \\ bb "" ;
Form feed
cout<<"" \\ ff "" ;
Newline
Newline Character
cout<<"" \\ nn "" ;
Carriage return
cout<<"" \\ rr "" ;
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 3/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
Tab
It gives a tab space
cout<<"" \\ tt "" ;
Backslash
It adds a backslash
cout<<"" \\ \\ "" ;
Single quote
It adds a single quotation mark
Question mark
It adds a question mark
cout<<"" \\ ?? "" ;
Octal No.
It represents the value of an octal number
cout<<"" \\ nn nn nn "" ;
Hexadecimal No.
It represents the value of a hexadecimal
number
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 4/21
cout<<"" \\ xx hh hh "" ;
3/31/25, 10:27 PM C + + Cheatsheet | CodeWithHarry
Null
The null character is usually used to terminate a string
cout<<"" \\ 00 "" ;
Comments
A comment is a code that is not executed by the compiler, and the
programmer uses it to keep track of the code.
Single line
comment
//// IItt''ss aa ssiinnggllee
lliinnee ccoommmmeenntt
Multi-line
comment
//**
IItt''ss
aa
mmuullttii
--lliinnee
ccoommmmee
Declaring
nntt
String
**//
Strings
ssttrriinngg lliibbrraarryy
It is##aiinncclluuddee
collection of
characters
<<ssttrriinngg>>
surrounded
append
by double
//// SSttrriinngg
quotes
function
vvaarriiaabbllee
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 5/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
It is used to concatenate two strings
""BBhhaaii"";
length function
It returns the length of the string
string variable1 =
Accessing
""CCooddeeWWand changing
iitthhHHaarrrryy""; string
characters
cout << "The length ooff tthhee ssttrriinngg
iiss:: variable1
string "" << variable1.l
= ""HHeellelelnlnogogtthh();
WWoorrlldd""; variable1[11] =
''ii'';
cout << variable1;
Maths
C++ provides some built-in math functions that help the
programmer to perform mathematical operations efficiently.
max function
It returns the larger value among the two
min function
It returns the smaller value among the two
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 6/21
3/31/25, 10:27 PM C + + Cheatsheet | CodeWithHarry
sqrt function
It returns the square root of a supplied number
##iinncclluuddee
<<ccmmaatthh>> cout
<<
ssqqrrtt(114444);
ceil function
It returns the value of
x rounded up to its
nearest integer
ddoouubbllee
a=cceeiill(11..99);
floor function
It returns the value of
x rounded down to
its nearest integer
If ddoouubbllee
a=fflloooorr(11..00
Statement
22);
iiff (condition) {
} eellssee {
if else-if
wwiillll ggeett eexxeeccuutteedd
Statement
}
iiff (condition) {
//// SSttaatteemmeennttss;;
}
//// SSttaatteemmeennttss;;
}
eellssee{
//// SSttaatteemmeennttss
}
Ternary Operator
It is shorthand of an if-else statement.
sswwiittcchh (expression)
{
ccaassee constant-
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 8/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
ccaassee constant-expression:
statement;
bbrreeaakk;
...
ddeeffaauulltt:
statement;
}
Iterative Statements
Iterative statements facilitate programmers to execute any block of
code lines repeatedly and can be controlled as per conditions added
by the programmer.
while Loop
It iterates the block of code as long as a specified condition is True
do-while loop
It is an exit controlled loop. It is very similar to the while loop with one
difference, i.e., the body of the do-while loop is executed at least once
even if the condition is False
ddoo
{
for loop
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 9/21
It is used to iterate the statements or a part of the program
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
Break Statement
break keyword inside the loop is used to terminate the loop
bbrreeaakk;
Continue Statement
continue keyword skips the rest of the current iteration of the loop and
returns to the starting point of the loop
ccoonnttiinnuuee;
References
Reference is an alias for an already existing variable. Once it is
initialized to a variable, it cannot be changed to refer to another
Creating
variable. So, it's a const pointer.
References
string var1 = ""VVaalluuee11""; //// vvaarr11
Pointers
Declaration
Pointer is a variable that holds the memory
address of another variable
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 10/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
datatype *var_name;
var_name = &variable2;
Function Definition
Recursion
Recursion is when a function calls a copy of itself to work on a
minor problem. And the function that calls itself is known as the
Recursive function.
vvooiidd rreeccuurrssee()
{
... .. ...
rreeccuurrssee();
... .. ...
}
Object-Oriented Programming
It is a programming approach that primarily focuses on using
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 11/21
nnaammee {
ppuubblliicc: ////
AAcccceessss
ssppeecciiffiieerr
//// ffiieellddss
object
//// ffuunnccttiioonnss
//// bblloocckkss
};
Class_name ObjectName;
Constructors
It is a special method that is called automatically as soon as
the object is created.
ccllaassss ccllaassssNNaammee
ssppeecciiffiieerr
ccllaassssNNaammee() { ////
""CCooddee WWiitthh
HHaarrrryy"";
}
};
iinntt mmaaiinn()
{ className
obj_name;
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 12/21
rreettuurrnn 00 ;
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
##iinncclluuddee<<iio
ossttrreeaamm>>
uussiinngg
nnaammeessppaaccee
std; ccllaassss
EExxaammpplleeEEnncca
app{ pprriivvaattee:
hhaavvee mmaarrkkeedd
tthheessee ddaattaa
mmeemmbbeerrss
pprriivvaattee,,
** aannyy
eennttiittyy
oouuttssiiddee
tthhiiss ccllaassss
ccaannnnoott
aacccceessss
Creating
tthheesseeand writing to a text
file** ddaattaa
mmeemmbbeerrss
##iinncclluuddee
ddiirreeccttllyy,,
<<iioossttrreeaamm>>
tthheeyy hhaavvee
#t
t #o
ioinn
ucuc
slsl
eueuddee
<g
g fe
<e st
ft tt
st re
te er
rr am
eaa am
n>n>
dd
** sseetttteerr
uussiinngg
ffuunnccttiioonnss..
nnaammeessppaaccee
**//
std;
iinntt
num;
iinntt mmaaiinn() {
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 13/21
/c
c /h
/h /aa
CrCr
rreeaattee aanndd ooppeenn
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
MyFile.cc ll oo ss ee ();
}
ggeettlliinnee()
Opening a File
It opens a file in the C++ program
mode);
in
Opens the file to read(default for ifstream)
out
Opens the file to write(default for ofstream)
binary
Opens the file in binary mode
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 14/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
ate
Opens the file and moves the control to the end of
the file
trunc
</> CodeWithHarry Logi
MenuRemoves the data in the existing file n
nocreate
Opens the file only if it already exists
noreplace
Opens the file only if it does not already exist
Closing a file
It closes the file
myfile.cc ll oo ss ee ()
Exception Handling
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 15/21
3/31/25, 10:27 PM C + + Cheatsheet | CodeWithHarry
ttrryy {
ccaattcchh () {
Add a new
comment
Post
Comment
Comments
(75)
talhaaziz2656 2025-02-13
Cheat sheet is not
downloading....
REPLY
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 16/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
pchahar865_gm 2025-02-09
Harry bhai download nhi ho rhi cheatsheet
REPLY
gyanprakash84758_gm 2025-02-07
Thanks Harry sir
REPLY
24227514010432_pa 2025-01-31
it is not downloading
REPLY
prashantthakur911975_gm 2025-01-26
cheatsheet download link is not work please fixed it
REPLY
adyuttrakhand345_gm 2025-01-20
Thank harry bhai
REPLY
sanilhinge_gm 2024-12-15
Cheatsheet Path :-
https://github.com/ayeujjawalsingh/Cheat-
Sheet/blob/master/C%2B%2B%20Cheatsheet%20-
%20CodeWithHarry.pdf
REPLY
yadavjagdeesh940_gm 2024-12-10
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 17/21
Thanks Harry bhaiya ❤
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
REPL
Y
nucleuseradigital_gm 2024-12-07
Hello Harry Sir, This file has downloading issue.
REPLY
nkkumar0234_gm 2024-11-26
Thank you sir
REPLY
ccodewithheet_gm 2024-10-28
Thankyou So Much Harry Bhai.
REPLY
wajdangujjar000_gm 2024-10-13
Those who are facing issue in downloading then the solution is
that 1. Open the cheatsheet on chrome 2. Press Ctrl + P that
we use actually for printing a document 3. A print dialogue
box will be shown 4. There in the upper right corner you will the
option of Destination and infront of which you are seeing
microsoft print to pdf 5. Click on the microsoft print to pdf
option and there you will see three option 6.One of them is
save as pdf and select it 7.Simply at the end save it where
ever you want
REPLY
kanhaiyalalchauhan934_gm 2024-09-27
Thank you
REPLY
ksemalaboys_gm 2024-09-15
Download nahi ho Raha hai
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 18/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
VIEW ALL
REPLIES
REPLY
hanzlaarshad539_gm 2024-09-11
Sir very good cheatsheet I'm thankful to you
REPLY
satishmourya072_gm 2024-09-08
Thanks sir
REPLY
varisali11292_gm 2024-09-05
C++ Cheat Sheet download link is not working.
Please fix it.
REPLY
mr.adeen946_gm 2024-08-28
Cheetsheet is not downloading
REPLY
sahilmandal7860786_gm 2024-08-28
Cheet Shit is not downloading. Please resolve this
bug
REPLY
yashvargaonkar_gm 2024-08-24
Site reach problem aa raha hai bhaiya
REPLY
rsk.edu960_gm 2024-
08-23
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 19/21
3/31/25, 10:27 C + + Cheatsheet | CodeWithHarry
PM
Harry vai , I am from Bangladesh. Maine aap ki videos see
he c and python sikh raha hu. Your way of teaching is just
phenomenal, jabardast!!! Bhai ek request this aap se ek
new C++ ki one shot video banao taki DSA acchi tarah se
kar saku.
REPL
Y
raushankumar6203961_gm 2024-07-21
Harry Bhai C++ ka cheatsheet download nhi ho raha hai.
REPLY
anoushijaz63_gm 2024-07-19
Harry bhai c++ ki cheatsheet download nhi ho parhi na
laptop sr or na android se koi error through kr rha hy firewall
ka....isy kse download kru?
REPLY
abhissss635_gm 2024-07-01
not able to download c and c++ cheat if any one can
provide pdf in comment it will be a great help
VIEW ALL REPLIES
REPLY
krish061521_gm 2024-06-16
#HarryBhai apki website me C language, C++, Java and
Flask ki cheatsheet download nahi ho rahi hai Maine cyber
cafe me jakar download kia waha par bhi nahi hua apki
website me kuchh technical issues hai isliye cheatsheet
download nahi ho rahi hai please aap jaldi se is problem ka
solution laaiye
REPLY
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 20/21
3/31/25, 10:27 C + + Cheatsheet |
PM CodeWithHarry
CodeWithHarry
Managed by CWH Privacy Terms Shop Contact
Solutions Refund
https://www.codewithharry.com/blogpost/cpp-cheatsheet/ 21/21