C++ Tutorial: Day 2
h
HahaYes (1212)

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.

You are viewing a single comment. View All
Muffinlavania (1194)

@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!

Muffinlavania (1194)

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

Muffinlavania (1194)

@HahaYes shrug whatever but anyway cool tutorial

HahaYes (1212)

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

Muffinlavania (1194)

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

Muffinlavania (1194)

@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"):

HahaYes (1212)

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

Muffinlavania (1194)

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

HahaYes (1212)

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