C++ Tutorial: Day 4!
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
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.
real meaning to this
so @hahayes can get free cycles
jk these are great
@awesome10 hmmm conspiracy theories 101
@HahaYes haha yes
@awesome10 yesssss
@HahaYes haha yes definitely
@awesome10 Mr.Stark I don't feel so good
@HahaYes am i overdoing this?...
@HahaYes um ok
@awesome10 HahayesssSSSSsssss
@HahaYes "AHH its a creeper!"
@Muffinlavania Muffin is > HahaYes
@HahaYes :D I dont think so... The power of the Haha yes is strong with this this one
@Muffinlavania yesssssss
@Muffinlavania yessss
@Muffinlavania haha yes
Make day 5 about manual GC and pointers.
@Jakman but no.... because ummmm uh...... too complicated for beginners? I haven't even finished like teaching them about loops + arrays
@HahaYes this is cpp. This isnt built for fragile minds.
@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
@HahaYes thats sad
@HahaYes why do you think people are still learning python?
@Jakman what the heck is a 'manual gc and pointers'?
@Jakman ummm data science?
@awesome10 google them. It would take a long time to explain. i would expect you know because you know C++.
@Jakman i know cpp, but not very well... :\
@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.
@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.
@Jakman Oh nice, someone in this community actually knows advanced C++
@Jakman oh ok i was about to google
@awesome10 that doesnt even make sence does it?
@HahaYes actually i know this from rust. It requires memory saftey so you need to know these concepts.
@HahaYes sorry to dissapoint you about my Cpp
@Jakman ya kinda doesnt...
@Jakman 2 months? It took me 5!
@ipastrano we all learn in different speeds.
@HahaYes that is inaccurate
@awesome10 lol i gave him another one too
@Muffinlavania NOOO WHY
@HahaYes hehehe
@Muffinlavania haha yes
@Muffinlavania hey you have exactly 365 cycles! That is pretty cool. Last time I checked you had 288
@HahaYes wait i do pls no one like my comment then
@Muffinlavania yes screenshot it
@HahaYes lol ok
@Muffinlavania yessssss now let me get to work
@Muffinlavania I am procrastinating so hard
@HahaYes You STILLL haven't studied? i thought you have been, i never see you actively coding, maybe because i cant lol
@HahaYes I was gonna ask you if you want to make some "Ai" but no you study boi
@Muffinlavania Hey, I'm back, you want to make that AI of yours?
@HahaYes lol ummm maybe?? im probably not gonna work on it a lot rn, its for tic tac toe
Can we do functions?
@SpaceFire yeah why not
YYAAAAAAYYYYY!
We want pointers we want pointers. Screw the pykids. We want pointers.
@Jakman ummm ok pointers
@HahaYes that's illegal
@Jakman lol all these python kids are kinda bad
@HahaYes yeah we need a content cop on this site.
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
@dillonjoshua68 on this site it is easy to exploit its easyness to make a low quality proj look good to retards.
Oh ok 😅, but again, it only looks hard for some people becuz their doing GCSE level computer science @Jakman
@dillonjoshua68 The amount of 10 year old pytards here is astounding.
I guess so @Jakman
@Jakman, what do you suggest I learn after augmenting my skills in python?
Cpp (I rlly like it) or NodeJs, or Ruby?
@dillonjoshua68 Either Java or C. Be prepared for headache.
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
@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.
Sure, but specifically which concepts? @Jakman Modules?
Matrix, etc... @Jakman
@dillonjoshua68 OOP,Auto GC, dynamic typing, etc...
Oh ok, thanks, currently I’m doing OOP @Jakman
What about recursive function? @Jakman
@dillonjoshua68 keep learning Python.
@dillonjoshua68 Lol noone uses recursion.
So recursion is pretty useless? @Jakman
I’m interested in cybersecurity, what bout u? @Jakman
@dillonjoshua68 nah. I do not like DevOps. The military will make you their slave man.
Oh ok lol, idk I’m gonna pursue ethical hacking, but I’m also opting for Machine [email protected]
@dillonjoshua68 Alright. Learn your basics first. Also ML makes you learn a lot of math. (including Calculus)
Oh ok, I guess I could do that, since I’m set 1 maths, so we’re doing higher level maths @Jakman
for(int vIndex = 0; vIndex < 4; vIndex++)
{
cout << trucks[vIndex];
}
@PatrickPIGNOL upvote!
Next tutorial coming very very fast......
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).
@SpaceFire lol I'm SICK
Hey man. Dont you hate it when people say C and Cpp are low level languages. They are very high level.
@Jakman Yeah, assembly is low language. I consider Cpp and C somewhere between like low and high
@HahaYes true. C is high level so is Cpp. Python is straight english.
@Jakman Python is english. That's why it is basically useless
@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 yes...
@HahaYes people will get real quiet if a post about pythons easiness is made
@Jakman yeah... I have a question... in Competitive programming, should I use python? (I use C++)
@HahaYes That would work nicely compared to python.
@Jakman yeah that would suck
@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.
@Jakman yeah, competitive programming is insane
@Jakman Then what is low level?
@CodeLongAndPros hex,binary,turing machines, the metal.
@CodeLongAndPros and dont forget the periodic table.
@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
@Jakman So is BF high level?
@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.
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]
@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
@CodeLongAndPros BF is low-level. Gifted minds are needed for such a language
@Jakman yesssss
@Jakman But there's automatic memory management!
@CodeLongAndPros hmm this is better than automatic memory managment
https://www.youtube.com/watch?v=OWWu05YYbNI
@CodeLongAndPros Hmmm @HahaNo exists
C Wars, Chapter One: The Segfault menace has been released to the public!
@CodeLongAndPros wait what
I don’t like cpp
This tutorial is cool, Maybe i can understand cpp.
I volunteer as writer!
@CodeLongAndPros hmmm paid not volunteered but I think I already sent the link
Seriously tho teach about pointers soon.
I'm willing to voulenteer(did i spell that right?), no need for cycle payment
@ipastrano are you good at cpp?
@HahaYes Moderately, sorry I've been afk due to personal reasons.
@ipastrano yo hey
@HahaYes yeah, I'm moderately good at c++, I'd love to join :)
@HahaYes so do you send invite or something else?
Very helpful! Thanks!
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
@SpaceFire where dat semicolon
@SpaceFire sorry, forgot about the semicolon
@HahaYes lmao the semi-colon was there it still needs std::
@SpaceFire hmmmm what did you do wrong
@HahaYes what looks wrong?
@SpaceFire hmmm first use using namespace std; first
@SpaceFire also why google analytics?
@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
@SpaceFire hmmm can you invite me?
@HahaYes idk, the council will decide your fate. Luckily the council is active right now.
@SpaceFire what is this site?
@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?)
@HahaYes thanks for the help namespace was missing XD
@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
@HahaYes using namespace std;
isn't a very good practice, because someday you may have to pull from other namespaces.
@ipastrano what does this mean? (sorry i am inexperienced)
@ipastrano using namespace std; is awesome
@HahaYes are you still interested in helping with the website
@SpaceFire um kinda but not really
@HahaYes ok then let us know when/if you ever are...
WHY IS C++ so HARD
@WhyMe2 C++ is hard bECAUSE you SHOULD HAVE LEARNED PYTHON
@HahaYes ROASTED
@WhyMe2 you think this is hard?
@Jakman lol stop the commenting gotta get to working on a Python Project (data science?)
@HahaYes alright.
@Jakman see ya
@adityaru @Muskan786 @DamienKilduff @AshishSarkar @mkhoi @TheForArkLD @DigitCommander @Jakman @Muffinlavania @WhyMe2 @awesome10 @DannyIsCoding @SpaceFire Day 5 is OUT!
@HahaYes I am going in for the judges opinon
@Jakman what do you mean
@HahaYes lol wait is @WhyMe2 your alt?
@Muffinlavania yes.... also day 5 is out
@Muffinlavania it is a bot
@Muffinlavania dang muffin you are gaining
@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 wat, im cool now :D
@Muffinlavania yes why not just comment
@Muffinlavania yeah, check it out, you are on the top 10
@HahaYes AYYYYY LEADERBOARD BOISSSSSSSSSSSSSSSSSSSSS
@HahaYes but i probably am gonna not post stuf so likeeeeee cya
@Muffinlavania AYYYYY CHECK OUT MY DAY 5
@Muffinlavania check out day 5 first
@HahaYes omg ok ok
@Muffinlavania we need to beat @CodeLongAndPros
@HahaYes OMG lolllll you cant stop advertising can ya
@HahaYes well he hacker boi and you kinda just brought him over here by the mention :(
@Muffinlavania nope
@HahaYes I can hear you.
@HahaYes SO umm @CodeLongAndPros your the best yay
@Muffinlavania oh well, he is offline
@CodeLongAndPros wait wait he is online ABORT ABORT ABORT
@Muffinlavania no no no no
@HahaYes shrug idk if you want i can stop talking if you are doing something
@Muffinlavania lol just go see day 5 and upvote
@HahaYes ......
@HahaYes And I've bookmarked this page.
@Muffinlavania oof oof DAY 5
@CodeLongAndPros ABORT ABORT ABORT
@HahaYes omg stop geeeeeeeeeeeeeeeeeeeeeez
@Muffinlavania oh no i have lost another comrade
@Muffinlavania hehe truck go boom boom
@HahaYes ...
@Muffinlavania hmmm free advertisement day 5 is OUT
@HahaYes
https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757https://repl.it/talk/learn/C-Tutorial-Day-5/42757
@HahaYes ya happy
@Muffinlavania the link broke
@Muffinlavania anyways, actually go check out day 5, ima be sick
Your move, @HahaYes
@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
@CodeLongAndPros wdym ABORT ABORT ABORT see ya
@HahaYes export mailto=/etc/crontab
@HahaYes E