What is a const? 🚫

preview_player
Показать описание
#const #keyword #programming

Const keyword C++ tutorial example explained
Рекомендации по теме
Комментарии
Автор

#include <iostream>

int main() {
const double PI = 3.14159;
//PI = 420.69; This will cause an error
double radius = 10;
double circumference = 2 * PI * radius;

std::cout << circumference << "cm";

return 0;
}

BroCodez
Автор

since i arrived early it's likely that you'll read this, you've taught me almost everything i know about programming, really easy to understand videos, keep it up man

kottln
Автор

While taking notes on this video, I included: const double Gravity = 9.8 ;

I just started teaching myself programming this week, using c++ and just on command line. Even though my interface is less intuitive than yours, this playlist has been a huge help for daily studying. I can see myself referencing these videos for a long time.

jamesmiller
Автор

For people who aren't aware... the const keyword is contextual. Const before a variable makes it constant, but const after a function declaration in a class makes it so that the method can be called with a const object. Anyway, good video!

cazz
Автор

constant: my knowledge of c++ even after watching the playlist about 12 times

Thisisdcode
Автор

Your series is super insightful and I am enjoying learning this so much!


#include <iostream>

int main () {

const double PI = 3.14159;
double radius = 10;
double circumference = 2 * PI * radius;

std:: cout << circumference << "cm";

return 0;
}

dawidbakkes
Автор

const string u = you are teaching good;

gourish
Автор

Thank you so much for returning to YouTube

cayden
Автор

as far as I think he never took a break. the time he did not upload he was making the videos he is uploading now. thanks bro :thumbsup: u truly r a chad





#simp lol

rudrarajkar
Автор

Im going off to a college soon, studying CE. A friend of mine reccommened your channel and it's been great so far, thanks for the great tutorial bro!

here's my homework

#include <iostream>

int main(){

//The const keyword spectifies that a variable's value is 'constant'
//tells the compiler that this value is off limits (prevent anything from modifying it)
// effectively a 'read-only'

double Torque = 318;
Torque = 69; //75 years since last oil change
int RPM = 5200;
double Horsepower = Torque * RPM / 5252 ;

std::cout << Horsepower << " HP\n";

//const prevent variable's value from being modified

const double turning_force = 318;
//turning_force = 420.69; //modifying the value just gonna cause an error
double powah = turning_force * RPM / 5252 ;

std::cout << powah << " HP";

return 0;
}

ryancoopersnissansx
Автор

#include <iostream> int main { using namespace std; const int age = 16; const double mark = 9.5; const string name = "Artemius"; const char grade = '11'; cout << age << years old << endl << mark << '\n' << name << endl << grade << "." }

artemzakharchuk
Автор

const int NUM_LEVELS = 25; // total levels in a game

const double FREEZING_POINT = 0; // celsius
const double BOILING_POINT = 212; // fahrenheit

const int DAYS_PER_WEEK = 7;
const int DAYS_PER_YEAR = 365;

const char FIRST_INITIAL = 'G';
const char LAST_INITIAL = 'B';

const std::string FIRST_NAME = "Gus";
const std::string LAST_NAME = "Burton";

const bool IS_ALIVE = true; // gonna live forever obviously

gusgus
Автор

#include <iostream>

int main(){
/**
The const keyword is used to define a variable that is CONSTANT and will not change
IE C for example (Speed of light) does not change in physics.
neither does g, 9.8 M/S/S

Prevents the compiler from allowing changes, makes it essentially read only
**/

const double PI = 3.1415926535898; //Naming convention for constants is all upper case.
double radius = 10;
double circum = 2 * PI * radius;
double areacir = PI * radius * radius;
double area = 4 * PI * radius * radius;
double volume = (4 * PI * radius * radius * radius) / 3;


std::cout << "Radius of circle " << radius << '\n';
std::cout << "Circumference of circle " << circum << '\n';
std::cout << "Area of a circle " << areacir << '\n';
std::cout << "Area of a sphere " << area << '\n';
std::cout << "Volume of a sphere " << volume << '\n';

return 0;
}

added some fun

Dr.Logistik
Автор

#include <iostream>

using namespace std;

int main() {
const int daysPerWeek = 7;
const int hoursPerDay = 24;
const int inchesPerFoot = 12;
const int feetPerMile = 5280;
const int secondsPerMinute = 60;

cout << daysPerWeek << endl;
cout << hoursPerDay << endl;
cout << inchesPerFoot << endl;
cout << feetPerMile << endl;
cout << secondsPerMinute << endl;

return 0;
}

// Just a few examples I could come up with. Could put many more though lol.

fxs-_-
Автор

you can use "using namespace std ; " after "include" instead of using "std::" in every line

arooba
Автор

Hey man, love your stuff. Keep up the good work!

ethangordon
Автор

const std::string LEGEND = "Bro Code";

joopa
Автор

Const double gravity = 9.8;
Const std::string legend ="Brocode"

SudiptaBadhon
Автор

thx for all your great content man, helped me a lot keep it up

alessandrogeiss
Автор

//Euler's number
const double E = 2.71828

ItsAstreo