Learn to Code via Tutorials on Repl.it!

← Back to all posts
C++ Tutorial: Day 4!
h
HahaYes (1052)

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.

Commentshotnewtop
Jakman (377)

@HahaYes I am going in for the judges opinon

HahaYes (1052)

@Muffinlavania dang muffin you are gaining

Muffinlavania (735)

@HahaYes wait day 5 is out???? I had no idea?? Also i was gonna ask y u literally answered right away, but ur sick right :(

HahaYes (1052)

@Muffinlavania yeah, check it out, you are on the top 10

Muffinlavania (735)

@HahaYes AYYYYY LEADERBOARD BOISSSSSSSSSSSSSSSSSSSSS

Muffinlavania (735)

@HahaYes but i probably am gonna not post stuf so likeeeeee cya

Muffinlavania (735)

@HahaYes OMG lolllll you cant stop advertising can ya

Muffinlavania (735)

@HahaYes well he hacker boi and you kinda just brought him over here by the mention :(

HahaYes (1052)

@CodeLongAndPros wait wait he is online ABORT ABORT ABORT

Muffinlavania (735)

@HahaYes shrug idk if you want i can stop talking if you are doing something

HahaYes (1052)

@Muffinlavania lol just go see day 5 and upvote

CodeLongAndPros (963)

@HahaYes And I've bookmarked this page.

Muffinlavania (735)

@HahaYes omg stop geeeeeeeeeeeeeeeeeeeeeez

HahaYes (1052)

@Muffinlavania oh no i have lost another comrade

HahaYes (1052)

@Muffinlavania hmmm free advertisement day 5 is OUT

HahaYes (1052)

@Muffinlavania anyways, actually go check out day 5, ima be sick

Muffinlavania (735)

@HahaYes arent you sick..... and also i did and upvoted, but likeeeeee my mommy said to watch out for baddies online


Hopefully you know im kidding

HahaYes (1052)

@CodeLongAndPros wdym ABORT ABORT ABORT see ya

Jakman (377)

Make day 5 about manual GC and pointers.

HahaYes (1052)

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

Jakman (377)

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

HahaYes (1052)

@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 (377)

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

awesome10 (212)

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

Jakman (377)

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

awesome10 (212)

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

Jakman (377)

@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 (377)

@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 (1052)

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

awesome10 (212)

@Jakman oh ok i was about to google

Jakman (377)

@awesome10 that doesnt even make sence does it?

Jakman (377)

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

Jakman (377)

@HahaYes sorry to dissapoint you about my Cpp

oignons (268)

@Jakman 2 months? It took me 5!

Jakman (377)

@ipastrano we all learn in different speeds.

Muffinlavania (735)

@awesome10 lol i gave him another one too

HahaYes (1052)

@Muffinlavania hey you have exactly 365 cycles! That is pretty cool. Last time I checked you had 288

Muffinlavania (735)

@HahaYes wait i do pls no one like my comment then

HahaYes (1052)

@Muffinlavania yessssss now let me get to work

HahaYes (1052)

@Muffinlavania I am procrastinating so hard

Muffinlavania (735)

@HahaYes You STILLL haven't studied? i thought you have been, i never see you actively coding, maybe because i cant lol

Muffinlavania (735)

@HahaYes I was gonna ask you if you want to make some "Ai" but no you study boi

HahaYes (1052)

@Muffinlavania Hey, I'm back, you want to make that AI of yours?

Muffinlavania (735)

@HahaYes lol ummm maybe?? im probably not gonna work on it a lot rn, its for tic tac toe

Jakman (377)

We want pointers we want pointers. Screw the pykids. We want pointers.

HahaYes (1052)

@Jakman lol all these python kids are kinda bad

Jakman (377)

@HahaYes yeah we need a content cop on this site.

dillonjoshua68 (66)

Pretty much cuz they are people who started programming recently, I’m nearly done with my first year of Computer science, and it’s in grade 10, the school wanted us to use python, since it’s a quick, ez, object-oriented programming language @HahaYes

Jakman (377)

@dillonjoshua68 on this site it is easy to exploit its easyness to make a low quality proj look good to retards.

dillonjoshua68 (66)

Oh ok 😅, but again, it only looks hard for some people becuz their doing GCSE level computer science @Jakman

Jakman (377)

@dillonjoshua68 The amount of 10 year old pytards here is astounding.

dillonjoshua68 (66)

@Jakman, what do you suggest I learn after augmenting my skills in python?
Cpp (I rlly like it) or NodeJs, or Ruby?

Jakman (377)

@dillonjoshua68 Either Java or C. Be prepared for headache.

dillonjoshua68 (66)

I sure will be ready... I mean u can understand how newbies struggle a lot in the beginning at python [email protected] I’ll do a comparison between them and choose one

Jakman (377)

@dillonjoshua68 Be sure to know the concepts of Python well. Not everything is done for you. Python is going to hold your hand in ways you will regret.

dillonjoshua68 (66)

Sure, but specifically which concepts? @Jakman Modules?

Jakman (377)

@dillonjoshua68 OOP,Auto GC, dynamic typing, etc...

dillonjoshua68 (66)

Oh ok, thanks, currently I’m doing OOP @Jakman

dillonjoshua68 (66)

What about recursive function? @Jakman

Jakman (377)

@dillonjoshua68 Lol noone uses recursion.

dillonjoshua68 (66)

So recursion is pretty useless? @Jakman

dillonjoshua68 (66)

I’m interested in cybersecurity, what bout u? @Jakman

Jakman (377)

@dillonjoshua68 nah. I do not like DevOps. The military will make you their slave man.

dillonjoshua68 (66)

Oh ok lol, idk I’m gonna pursue ethical hacking, but I’m also opting for Machine [email protected]

Jakman (377)

@dillonjoshua68 Alright. Learn your basics first. Also ML makes you learn a lot of math. (including Calculus)

dillonjoshua68 (66)

Oh ok, I guess I could do that, since I’m set 1 maths, so we’re doing higher level maths @Jakman

PatrickPIGNOL (0)

for(int vIndex = 0; vIndex < 4; vIndex++)
{
cout << trucks[vIndex];
}

HahaYes (1052)

Next tutorial coming very very fast......

SpaceFire (101)

Man do i sure love a Day 5

OH WAIT

... lol jk take your time
(BTW if you find these rare prompts annoying let me know... I will stop).

Jakman (377)

Hey man. Dont you hate it when people say C and Cpp are low level languages. They are very high level.

HahaYes (1052)

@Jakman Yeah, assembly is low language. I consider Cpp and C somewhere between like low and high

Jakman (377)

@HahaYes true. C is high level so is Cpp. Python is straight english.

HahaYes (1052)

@Jakman Python is english. That's why it is basically useless

Jakman (377)

@HahaYes yeah. It has its uses. On this site you will usually see low quality posts made in python. In Cpp or any other Language of its complexity you will see only the highest of content.

Jakman (377)

@HahaYes people will get real quiet if a post about pythons easiness is made

HahaYes (1052)

@Jakman yeah... I have a question... in Competitive programming, should I use python? (I use C++)

Jakman (377)

@HahaYes That would work nicely compared to python.

Jakman (377)

@HahaYes nah that would not suck. Cpp gives you lots of control as compared to python. Just dont try to make any GUI's in it.

HahaYes (1052)

@Jakman yeah, competitive programming is insane

Jakman (377)

@CodeLongAndPros hex,binary,turing machines, the metal.

Jakman (377)

@CodeLongAndPros and dont forget the periodic table.

dillonjoshua68 (66)

@CodeLongAndPros there are 3 different types

High level - easiest/ closer to English
Assembly language - I’d consider Cpp here when comparing to python although I think it’s More of a high level language

Low level

CodeLongAndPros (963)

@dillonjoshua68 How it’s arranged:
High:
Anything with import, garbage collector, can be OOP.

Middle:
No garbage collector, pointers.

Low:
Uses CPU registers, obscure opcodes.

dillonjoshua68 (66)

Sorry for asking, but what does garbage collector, pointers, and obscure opciones mean? I’m in my first year of computer science, so idk, grade [email protected]

HahaYes (1052)

@dillonjoshua68 oh ummmmm basically garbage collecter makes a programming language safer. (of course Cpp doesn't that is why it is fast) pointers, look it up, and I have no clue obscure opciones mean

Jakman (377)

@CodeLongAndPros BF is low-level. Gifted minds are needed for such a language

CodeLongAndPros (963)

@Jakman But there's automatic memory management!

TheForArkLD (660)

I don’t like cpp
This tutorial is cool, Maybe i can understand cpp.

CodeLongAndPros (963)

I volunteer as writer!

HahaYes (1052)

@CodeLongAndPros hmmm paid not volunteered but I think I already sent the link

Jakman (377)

Seriously tho teach about pointers soon.

oignons (268)

I'm willing to voulenteer(did i spell that right?), no need for cycle payment

oignons (268)

@HahaYes Moderately, sorry I've been afk due to personal reasons.

oignons (268)

@HahaYes yeah, I'm moderately good at c++, I'd love to join :)

oignons (268)

@HahaYes so do you send invite or something else?

DigitCommander (31)

Very helpful! Thanks!

SpaceFire (101)

i would like to report an error (i am using replit for c++)

when i tried to make an array it would only accept it when i declared by array with

std::string arrayname[length]={"stuff","morestuff"}

exact same thing applies to cout

i do not like to see these kinds of errors in those i worship devoutly

HahaYes (1052)

@SpaceFire sorry, forgot about the semicolon

SpaceFire (101)

@HahaYes lmao the semi-colon was there it still needs std::

HahaYes (1052)

@SpaceFire hmmmm what did you do wrong

HahaYes (1052)

@SpaceFire hmmm first use using namespace std; first

HahaYes (1052)

@SpaceFire also why google analytics?

SpaceFire (101)

@HahaYes for now you don't need to know but probably in about next 3-10 days you should be hearing about our site across replit

HahaYes (1052)

@SpaceFire hmmm can you invite me?

SpaceFire (101)

@HahaYes idk, the council will decide your fate. Luckily the council is active right now.

SpaceFire (101)

@HahaYes physimx.tech however do to the fact we are changing our host the site is temporarily down but can be found here note the site is incomplete

SpaceFire (101)

@HahaYes the council has a question: are you joining us for your own purposes or to help push us forward (look around or become a dev?)

SpaceFire (101)

@HahaYes thanks for the help namespace was missing XD

SpaceFire (101)

@HahaYes we are a site who have collections of physics simulations. rn we don't have many soon we will make it so users can add sims

oignons (268)

@HahaYes using namespace std; isn't a very good practice, because someday you may have to pull from other namespaces.

SpaceFire (101)

@ipastrano what does this mean? (sorry i am inexperienced)

HahaYes (1052)

@ipastrano using namespace std; is awesome

SpaceFire (101)

@HahaYes are you still interested in helping with the website

HahaYes (1052)

@SpaceFire um kinda but not really

SpaceFire (101)

@HahaYes ok then let us know when/if you ever are...

Port8080 (0)

WHY IS C++ so HARD

HahaYes (1052)

@WhyMe2 C++ is hard bECAUSE you SHOULD HAVE LEARNED PYTHON

Jakman (377)

@WhyMe2 you think this is hard?

HahaYes (1052)

@Jakman lol stop the commenting gotta get to working on a Python Project (data science?)

firefish (308)

@WhyMe2 I thought you renamed youreslf to @Port8080 @HahaYes