Skip to content
← Back to Community
C++ Tutorial: Day 2
Profile icon
HahaYes

HahaYes' Very Good C++ Tutorial

Day 2!

Credits for Day 1 fixes and/or bugs.
@CodeLongAndPros

EDITS:

**** A elaboration on multi-line quotes

I realised that I never put in multi line quotes, so here it is.

/* This is a multi line quote you can put as many lines as you need but make sure to end it with... */

**** A elaboration on int main() (Thank you to @CodeLongAndPros)

What is int main()?

To answer that question, we need to first look at what C++ is.
(I use C and C++ to refer to the same thing)

C is compiled to machine code.

So is assembly code. Assembly code is pretty much the lowest level your code can be.

In the ELF, it needs an entry point. This can be anything with the entry foo command.

So, when GCC compiles C to machine code, it uses ENTRY main in the assembly code.

This is why you need to have an int main in your code.


Day 2! of C++ BootCamp!

Topic: Variables!

What are variables?

Variables are containers for storing data values.
C++ Variables include....
bool(boolean): true or false?

int(integer): stores integers without decimals. (Ex: 111 or -111)

double: stores floating point integers. (Ex: 19.99) it has about 15 digits of precision.

float: also stores floating point integers. (Ex: 19.99) it as about 7 digits of precision.

char(character): stores single characters. (a, b, c, A, B, C, etc.) it is surrounded by single quotes. ''

string: stores text. (Cybertruck) it is surrounded by double quotes.

Example of variables in code:

#include <bits/stc++.h> using namespace std; int main() { // This is a comment int cybertruck = 30; cout << cybertruck << "\n"; bool isItraining = false; cout << "hahayes" << endl; double lotsofDecimals = 15.55555555555555; float lotsofDecimalstoo = 15.5555555; string stringcheese = "cheese"; char alphabet = 'a' cout << lotsofDecimals << lotsofDecimalstoo << stringcheese << alphabet << endl; return 0; // voila! bunch of variables }

Because C++ is a statistically typed language, you have to declare if a variable is int, double, char, float, etc..
This is a reason that C++ is kinda hard.


That's it!

Please Upvote!

Oh lol I guess this is a 200 cycle celebration too

Sorry guys, Day 3 delayed for a little bit. I will post day 3 and 4 tommorow!

THis has turned into a 300 cycle celebration too. Oh well...
This has turned into a 400 cycle celebration too. Yikes....

Totally not procrastinating and not posting anything. (jk I'm just taking a break.

Voters
Profile icon
Kurikin
Profile icon
Behemoth58777
Profile icon
PrajwolBasyal
Profile icon
RamnSnchez
Profile icon
cmerrill
Profile icon
WILLIAMBAEWER
Profile icon
ia13ru
Profile icon
LitteJohn
Profile icon
BenFord
Profile icon
DigitCommander
Comments
hotnewtop
Profile icon
HahaYes

Thanks for 200 cycles guys!

Profile icon
CodeLongAndPros

@HahaYes Glad to 27 91 65vote your post.

Profile icon
HahaYes
Profile icon
CodeLongAndPros

@HahaYes The triplet (27, 91, 65) is the up arrow.

Profile icon
HahaYes
Profile icon
HahaYes

@CodeLongAndPros Hey CodeLong, I just sent you the multiplayer REPL that is going to be based off of Cactus' How to python website

Profile icon
Kookiez

@HahaYes lol a extra 100 cycles in a day! Whatttttt

Profile icon
DynamicSquid

@OrangeJooce123

I FOUND ORANGE JUICE GANG!

Profile icon
HahaYes

@DynamicSquid OH NO THE ORANGE JUICE

Profile icon
HahaYes

@DynamicSquid WHAT DO WE DO

Profile icon
HahaYes

@DynamicSquid WE NEED MILK

Profile icon
DynamicSquid
Profile icon
HahaYes

@DynamicSquid HAHA YES

Profile icon
HahaYes

@DynamicSquid I don't think the repl community likes my name

Profile icon
DynamicSquid

@HahaYes i like it

Profile icon
HahaYes

@DynamicSquid Look up the definition of hahayes

Profile icon
DynamicSquid

@HahaYes

oh lol

Profile icon
HahaYes
Profile icon
Kookiez

@DynamicSquid I LIKE ORANGE JOOCE AND MILK WITH COOKIES BUT NOT THE LEGO CYBERTRUCK

Profile icon
HahaYes

Thanks for 300 cycles guys!

Profile icon
HahaYes

hmmmmmmm I think we have a teacher here........

Profile icon
HahaYes
Profile icon
SpaceFire

@HahaYes Haha yes

Profile icon
DigitCommander

@HahaYes Can't find it

Profile icon
Jakman

Lol static typing does not make a language hard.

Profile icon
HahaYes

@Jakman harder than dynamically

Profile icon
Jakman

@HahaYes true but once you get used to it, it wont hurt.

Profile icon
DynamicSquid

You forgot #include <string> when using string variables

Profile icon
HahaYes

@DynamicSquid oh yeah.... I thought I put #include <bits/stdc++.h>
I will put that in the edit and thank you for next day

Profile icon
HahaYes

@DynamicSquid thanks squid

Profile icon
HahaYes

@DynamicSquid Mr.Squid do you want to help me make a series for this? Might make it more popular.

Profile icon
DynamicSquid

@HahaYes umm... I'm not sure. I would love to, but I'm really busy with time, and my schedule is always very spotty. I could help you with some things I suppose. Also why'd you keep calling me "mr.squid"? lol

Profile icon
HahaYes

@DynamicSquid I dunno. I guess it is funny.

Profile icon
HahaYes

@DynamicSquid Feel free to upvote?

Profile icon
Jakman

Also the lowest level that code can be other than binary is COBOL with punch_cards and a huge computer.

Profile icon
HahaYes

@Jakman I'm talking about languages that people actually use. Cobol, yes, punch cards and huge computers no

Profile icon
Jakman

@HahaYes in the 50s and 60s when writing Cobol you would punch a punch card and enter it into a huge computer to compile and execute the code.

Profile icon
awesome10

can you do conditionals? (like if and else) (im a pythoner ok?)

Profile icon
HahaYes

@awesome10 yeah... possibly day 4... maybe day 3... I'll have to see

Profile icon
awesome10

@HahaYes ok good can you do day 3 though? you dont need to rush it, i just really like conditionals (pls dont judge XD)

Profile icon
Jakman

@awesome10 no one here will judge unless you prompt them to judge you for laziness usually. Saying please don't judge will show insecurity among people who wish to take advantage. Here people will judge if you actually deserve to be. There is no penalty for success or being a beginner.

Profile icon
HahaYes

@Jakman yeah you are right

Profile icon
BenFord

Good stuff

Profile icon
HahaYes

@BenFord yeah np upvote

Profile icon
PotatoHeadz35

@HahaYes isn't it bad practice to use #include <bits/stc++.h>? Checkout this post.

Profile icon
HahaYes

@PotatoHeadz35 yes, but I like it myself :)

Profile icon
PotatoHeadz35

@HahaYes could you use the header for your tuts tho?

Profile icon
Muffinlavania

@HahaYes i guess your back on top lol it seems my tutorial got deleted somehow. Also, even though i dont really know any C, good tutorial!

Profile icon
HahaYes

@Muffinlavania Lol this is C++ but ok

Profile icon
Muffinlavania

@HahaYes yea isnt C++ like more specific and C is more general?

Profile icon
HahaYes

@Muffinlavania C is a language

Profile icon
Muffinlavania

@HahaYes shrug whatever but anyway cool tutorial

Profile icon
HahaYes

@Muffinlavania yeah. I keep on delaying my tutorials because I'm so busy. Oh well, I guess I will take a break this weekend

Profile icon
Muffinlavania

@HahaYes you should! Sorry im making a Tic Tac Toe game rn so i might not respond immediately

Profile icon
HahaYes

@Muffinlavania Well have fun!

Profile icon
Muffinlavania

@HahaYes Haha YES i will

Profile icon
HahaYes

@Muffinlavania YESSSSSSSSSSSsssss

Profile icon
Muffinlavania

@HahaYes lol i thought you wouldnt like my pun
also this is why i didnt respond right away

if (board_slots[0]=="O" and board_slots[1]=="O" and board_slots[2]=="O") or (board_slots[0]=="O" and board_slots[3]=="O" and board_slots[6]=="O") or (board_slots[1]=="O" and board_slots[4]=="O" and board_slots[7]=="O") or (board_slots[2]=="O" and board_slots[5]=="O" and board_slots[8]=="O") or (board_slots[3]=="O" and board_slots[4]=="O" and board_slots[5]=="O") or (board_slots[6]=="O" and board_slots[7]=="O" and board_slots[8]=="O") or (board_slots[0]=="O" and board_slots[4]=="O" and board_slots[8]=="O") or (board_slots[2]=="O" and board_slots[4]=="O" and board_slots[6]=="O"):

Profile icon
HahaYes

@Muffinlavania oh cool! You want me to help you with your project?

Profile icon
Muffinlavania

@HahaYes i mean im pretty much finished, but if you want sure ill share you in

Profile icon
HahaYes

@Muffinlavania yeah just share it with me if you want to