Learn to Code via Tutorials on Repl.it!

← Back to all posts
SHORT C++ Tutorial Pt1: The Basics
SilentShadowBla (538)

This may be a little confusing for some people...

Short Tutorial on the [The Basics] of C++.

Hope you enjoy!
FULLSCREEN HERE

Commentshotnewtop
ChimaNwosu1 (6)

I've literally been trying to learn how to print text slow, this repl taught me how to use user input and how to get any key input. Good looks!

anotherthel (0)

There are tons of types of functions, such as bool, etc. And with libraries like <vector> there are functions like say

std::vector<int> func(){// this returns an int vector}

CSharpIsGud (414)

there are generally only 2 types of functions, 'void' and 'int'

Adding on to @DynamicSquid 's comment
Functions can have many return types. you have things like std::string, std::map instances of your own classes and many many many more from the standard libraries.

DynamicSquid (2025)

@CSharpIsGud But she was referring to the main ones.

anotherthel (0)

@DynamicSquid well you could say that bool and float and double are "main ones".

DynamicSquid (2025)

@anotherthel well sure. I guess it varies though between people and what you do

anotherthel (0)

@Highwayman well u could say the only main one is the one u actually need, which yes, is int

anotherthel (0)

@Highwayman i meant main by included so like bool float whatever

Highwayman (1309)

@anotherthel ik I was just joking around :P

CSharpIsGud (414)

@anotherthel you need every primitive type

DynamicSquid (2025)

there are generally only 2 types of functions, 'void' and 'int'

What about bool?

AmazingMech2418 (658)

@DynamicSquid Well, bool is only in C++. If you are doing C, you can't do bool. However, what I think should be added is char.

DynamicSquid (2025)

@AmazingMech2418 where would you use a char return type?

AmazingMech2418 (658)

@DynamicSquid Well, I've at least used the char* type for strings in C, but the base of that is char.

DynamicSquid (2025)

@AmazingMech2418 Oh character pointers! I though you were just referring to regular char. Yeah, I guess that's true

anotherthel (0)

@AmazingMech2418 Yeah c is weird im pretty sure you have to include stdbool.h or something

AmazingMech2418 (658)

@anotherthel I just use 1 and 0 to represent true and false in C.

anotherthel (0)

@AmazingMech2418 oh. i didnt know that i use c++.

DynamicSquid (2025)

@anotherthel C++ also supports 0 and 1 as false and true

anotherthel (0)

oh i just use true false asa its included @DynamicSquid

DynamicSquid (2025)

@anotherthel yeah same, I don't like the look of 1s and 0s

AmazingMech2418 (658)

@DynamicSquid WOW! That was a lot faster than I thought it would be... I thought it would be like a month until I got 100 cycles. Also, thank you!

CSharpIsGud (414)

@DynamicSquid char's can hold single characters when you don't need a string or a pointer, and char's in C and C++ represent bytes

DynamicSquid (2025)

@CSharpIsGud yeah I know that... were you responding to this comment: "where would you use a char return type?"

For that I meant where would you commonly use a char return type?

CSharpIsGud (414)

@DynamicSquid Anywhere you need to return a byte, or just to represent a character. like a function to read a byte from something

DynamicSquid (2025)

@CSharpIsGud Well yes, I know that, but what I mean by "main" ones are functions with another purpose. I guess it really depends on how you define "main" but for me "bool" is a major one since STL algorithms and stuff. "void" is also a major one. It really depends