C++ Tutorial: Day 4!
h
HahaYes (1901)

Day 4 of C++ Tutorials!

EDIT: Willing to hire people for this for 7 cycles per post. "A cycle a day keeps unemployment away!" - @CodingCactus

Devoted Follower

@SpaceFire !

Very devoted follower is him!

Day 4 is about........ ummmm......

Operators!

Every Single Operator(for beginners)

>  means greater than
>=  means greater than or equal to
< means less than
<= means less than or equal to
== means equal to
!= means not equal to

These are basically the operators that you need. You will need &&, ||, and ! in the future but not now.


Arrays!

Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.

To declare an array, define the variable type, specify the name of the array followed by square brackets and specify the number of elements it should store:

string trucks[4]; (delete this before you run the next line)
// this is a comment
// 4 states how many objects will be in the array.
// to store arrays, just add these brackets{} afterward.

string trucks[4] = {"Cybertruck", "Ford F-150", "Chevrolet", "GMC"}; (Truck companies don't sue me)

And of course, you can use int, char, double, float to subsitute for "string".
so you can do stuff like this...

int numbers[4] = {1, 2, 3, 4};

And to "print" (cout) these things, just do,

#include <bits/stdc++.h>
using namespace std;
int main()
{
	string trucks[4] = {"Cybertruck", "Ford F-150", "Chevrolet", "GMC"}; (Truck companies don't sue me)
	cout << trucks[0]; // this will print out Cybertruck. 
	/* Note: trucks[4] states how many objects is in the brackets,
	but [0] will always be the first element. [1] will be the second, etc.
	*/
	return 0;
	
}
Sorry for the delay guys!

If there are any bugs/typos, please let me know in the comments below.

Shoutout..... @DynamicSquid "rebellious people are losers."

Ummmmm Day 5 is probably about arrays and loops.

You are viewing a single comment. View All
Jakman (473)

Make day 5 about manual GC and pointers.

HahaYes (1901)

@Jakman but no.... because ummmm uh...... too complicated for beginners? I haven't even finished like teaching them about loops + arrays

Jakman (473)

@HahaYes this is cpp. This isnt built for fragile minds.

HahaYes (1901)

@Jakman sadly it seems like some people go THIS IS TOO COMPLICATED in python, I'm kinda scared what will happen if I do a complex pointer in cpp

Jakman (473)

@HahaYes why do you think people are still learning python?

awesome10 (233)

@Jakman what the heck is a 'manual gc and pointers'?

Jakman (473)

@awesome10 google them. It would take a long time to explain. i would expect you know because you know C++.

awesome10 (233)

@Jakman i know cpp, but not very well... :\

Jakman (473)

@HahaYes i mean that people are still learning python concepts after they have had months to figure them out. I mastered OOP in two months. Some people are still learning about classes that have thousands of cycles.

Jakman (473)

@awesome10 google those things. I will give a quick rundown. A refrence is the place in memory that a variable or method is stored.
A pointer is a variable that points to this refrence. Via this pointer, you can change the value of what ever it is pointing to.
(GC) or Garbage Collection is the process of getting rid of refrences. Let me give you a run down of that. Imagine that you declare a pointer to a variable before you make the variable.
The pointer and refrence live longer than what you are pointing to (the variable). When you use garbage collection you can get rid of the refrence and pointer so that you may have more memory storage and you can make another pointer. Pointers are used every time you need to override something or make a copy of something and return that thing.

HahaYes (1901)

@Jakman Oh nice, someone in this community actually knows advanced C++

awesome10 (233)

@Jakman oh ok i was about to google

Jakman (473)

@awesome10 that doesnt even make sence does it?

Jakman (473)

@HahaYes actually i know this from rust. It requires memory saftey so you need to know these concepts.

Jakman (473)

@HahaYes sorry to dissapoint you about my Cpp

oignons (324)

@Jakman 2 months? It took me 5!

Jakman (473)

@ipastrano we all learn in different speeds.