Learn to Code via Tutorials on Repl.it!

← Back to all posts
C++ Tutorial: Day 4!
HahaYes

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)

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:

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

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

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.

Voters
RamnSnchez
WILLIAMBAEWER
LitteJohn
BenFord
SelenaYang1
WilliamWu13
chrisrama
grace97464
DungeonMaster00
oignons
Comments
hotnewtop
HahaYes
Jakman

@HahaYes I am going in for the judges opinon

HahaYes

@Jakman what do you mean

Muffinlavania

@HahaYes lol wait is @WhyMe2 your alt?

HahaYes

@Muffinlavania yes.... also day 5 is out

HahaYes

@Muffinlavania it is a bot

HahaYes

@Muffinlavania dang muffin you are gaining

Muffinlavania

@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 :(

Muffinlavania

@HahaYes wat, im cool now :D

HahaYes

@Muffinlavania yes why not just comment

HahaYes

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

Muffinlavania

@HahaYes AYYYYY LEADERBOARD BOISSSSSSSSSSSSSSSSSSSSS

Muffinlavania

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

HahaYes

@Muffinlavania AYYYYY CHECK OUT MY DAY 5

HahaYes

@Muffinlavania check out day 5 first

Muffinlavania

@HahaYes omg ok ok

HahaYes
Muffinlavania

@HahaYes OMG lolllll you cant stop advertising can ya

Muffinlavania

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

HahaYes
CodeLongAndPros

@HahaYes I can hear you.

Muffinlavania

@HahaYes SO umm @CodeLongAndPros your the best yay

HahaYes

@Muffinlavania oh well, he is offline

HahaYes

@CodeLongAndPros wait wait he is online ABORT ABORT ABORT

HahaYes

@Muffinlavania no no no no

Muffinlavania

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

HahaYes

@Muffinlavania lol just go see day 5 and upvote

Muffinlavania

@HahaYes ......

CodeLongAndPros

@HahaYes And I've bookmarked this page.

HahaYes

@Muffinlavania oof oof DAY 5

HahaYes

@CodeLongAndPros ABORT ABORT ABORT

Muffinlavania

@HahaYes omg stop geeeeeeeeeeeeeeeeeeeeeez

HahaYes

@Muffinlavania oh no i have lost another comrade

HahaYes

@Muffinlavania hehe truck go boom boom

Muffinlavania
HahaYes

@Muffinlavania hmmm free advertisement day 5 is OUT

Muffinlavania
Muffinlavania

@HahaYes ya happy

HahaYes

@Muffinlavania the link broke

HahaYes

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

CodeLongAndPros

Your move, @HahaYes

Muffinlavania

@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

@CodeLongAndPros wdym ABORT ABORT ABORT see ya

CodeLongAndPros

@HahaYes export mailto=/etc/crontab

TheForArkLD
awesome10

real meaning to this
so @hahayes can get free cycles
jk these are great

HahaYes

@awesome10 hmmm conspiracy theories 101

awesome10

@HahaYes haha yes

HahaYes

@awesome10 yesssss

awesome10

@HahaYes haha yes definitely

HahaYes

@awesome10 Mr.Stark I don't feel so good

awesome10

@HahaYes am i overdoing this?...

awesome10

@HahaYes um ok

HahaYes

@awesome10 HahayesssSSSSsssss

awesome10

@HahaYes "AHH its a creeper!"

Muffinlavania
HahaYes

@Muffinlavania Muffin is > HahaYes

Muffinlavania

@HahaYes :D I dont think so... The power of the Haha yes is strong with this this one

HahaYes

@Muffinlavania yesssssss

Muffinlavania
HahaYes
awesome10
Jakman

Make day 5 about manual GC and pointers.

HahaYes

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

Jakman

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

HahaYes

@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

@HahaYes thats sad

Jakman

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

awesome10

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

HahaYes

@Jakman ummm data science?

Jakman

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

awesome10

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

Jakman

@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

@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

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

awesome10

@Jakman oh ok i was about to google

Jakman

@awesome10 that doesnt even make sence does it?

Jakman

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

Jakman

@HahaYes sorry to dissapoint you about my Cpp

awesome10

@Jakman ya kinda doesnt...

Jakman

@ipastrano we all learn in different speeds.

HahaYes

awesome10

@HahaYes that is inaccurate

Muffinlavania

@awesome10 lol i gave him another one too

HahaYes
Muffinlavania

@HahaYes hehehe

awesome10
HahaYes

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

awesome10
Muffinlavania

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

HahaYes

@Muffinlavania yes screenshot it

Muffinlavania

@HahaYes lol ok

Muffinlavania
HahaYes

@Muffinlavania yessssss now let me get to work

HahaYes

@Muffinlavania I am procrastinating so hard

Muffinlavania

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

Muffinlavania

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

HahaYes

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

Muffinlavania

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

SpaceFire

Can we do functions?

HahaYes

@SpaceFire yeah why not

SpaceFire

YYAAAAAAYYYYY!

Jakman

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

HahaYes

@Jakman ummm ok pointers

Jakman

@HahaYes that's illegal

HahaYes

@Jakman lol all these python kids are kinda bad

Jakman

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

dillonjoshua68

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

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

dillonjoshua68

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

Jakman

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

dillonjoshua68

I guess so @Jakman

dillonjoshua68

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

Jakman

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

dillonjoshua68

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

@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

Sure, but specifically which concepts? @Jakman Modules?

dillonjoshua68

Matrix, etc... @Jakman

Jakman

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

dillonjoshua68

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

dillonjoshua68

What about recursive function? @Jakman

Jakman

@dillonjoshua68 keep learning Python.

Jakman

@dillonjoshua68 Lol noone uses recursion.

dillonjoshua68

So recursion is pretty useless? @Jakman

dillonjoshua68

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

Jakman

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

dillonjoshua68

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

Jakman

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

dillonjoshua68

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

PatrickPIGNOL

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

HahaYes
JustAWalrus
HahaYes

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

SpaceFire

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).

HahaYes

@SpaceFire lol I'm SICK

Jakman

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

HahaYes

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

Jakman

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

HahaYes

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

Jakman

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

HahaYes

@Jakman yes...

Jakman

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

HahaYes

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

Jakman

@HahaYes That would work nicely compared to python.

HahaYes

@Jakman yeah that would suck

Jakman

@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

@Jakman yeah, competitive programming is insane

CodeLongAndPros

@Jakman Then what is low level?

Jakman

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

Jakman

@CodeLongAndPros and dont forget the periodic table.

dillonjoshua68

@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

@Jakman So is BF high level?

CodeLongAndPros

@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

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

@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

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

HahaYes

@Jakman yesssss

CodeLongAndPros

@Jakman But there's automatic memory management!

HahaYes

@CodeLongAndPros hmm this is better than automatic memory managment
https://www.youtube.com/watch?v=OWWu05YYbNI

CodeLongAndPros
HahaYes
Jakman
CodeLongAndPros

C Wars, Chapter One: The Segfault menace has been released to the public!

HahaYes
TheForArkLD

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

CodeLongAndPros

I volunteer as writer!

HahaYes

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

Jakman

Seriously tho teach about pointers soon.

DigitCommander

Very helpful! Thanks!

SpaceFire

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

exact same thing applies to cout

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

HahaYes

@SpaceFire where dat semicolon

HahaYes

@SpaceFire sorry, forgot about the semicolon

SpaceFire

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

HahaYes

@SpaceFire hmmmm what did you do wrong

SpaceFire

@HahaYes what looks wrong?

HahaYes

@SpaceFire hmmm first use using namespace std; first

HahaYes

@SpaceFire also why google analytics?

SpaceFire

@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

@SpaceFire hmmm can you invite me?

SpaceFire

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

HahaYes

@SpaceFire what is this site?

SpaceFire

@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

@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

@HahaYes thanks for the help namespace was missing XD

SpaceFire

@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

SpaceFire

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

HahaYes

@ipastrano using namespace std; is awesome

SpaceFire

@HahaYes are you still interested in helping with the website

HahaYes

@SpaceFire um kinda but not really

SpaceFire

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

HahaYes
Port8080

WHY IS C++ so HARD

HahaYes

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

awesome10

@HahaYes ROASTED

Jakman

@WhyMe2 you think this is hard?

HahaYes

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

Jakman

@HahaYes alright.

HahaYes

@Jakman see ya

firefish

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

Port8080