What is C++ type conversion? ✨

preview_player
Показать описание
C++ type conversion implicit explicit tutorial example explained

#type #conversion
Рекомендации по теме
Комментарии
Автор

#include<iostream>

int main()
{
// type conversion = conversion a value of one data type to another
// Implicit = automatic
// Explicit = precede value with new data type (int)

int correct = 8;
int questions = 10;
double score = correct/(double)questions * 100;

std::cout << score << "%";

return 0;
}

BroCodez
Автор

Bro you are Seriously Underated. When i get rich I won't forget you.

MilkyasMarkos
Автор

I really enjoy your examples. They keep my goldfish brain (-1 second) very engaged.

strtgyr
Автор

You are doing great work. It's crazy how the likes and comments drop off as the video series proceeds. Hoping I will make it to the end.

dawidbakkes
Автор

Your videos are well-explained. Thank you for your work!!

Zulal-hknq
Автор

Bro really this also you made me easy to understand

muzzammilsabuwala
Автор

thankuu so much for thi samazing contents . please upload more videos of full course

mariyaislambhuiyannidheid
Автор

Thank you so much! I am watching this entire series, on this video right now (video 7). I can't believe it. I'm seeing the views, likes, and comments go down the further in I go...

juliantomesheski
Автор

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

arooba
Автор

type casting on variables is something new! I am coming from Python (also thanks to your videos on that for file I/O and Tkinter) and this is not something I worked with really!

stonedorsey
Автор

type conversion is confusing i dont know why
int a=8;
int b=10;
double c=(double)a/b*100;

std::cout<<"\n"<<c<<" %";
return 0;
is giving same result of 80 % how??

honeman
Автор

// HERE IS MY OWN CODE WHILE LEARNING WITH BRO

#include <iostream>

// type conversion = convert the type of variable to another.
// It has two ways: implicit and explicit.

int main() {
// EXPLICIT CASTING
int integer = (double) 3.14;
int doubled = (int) 3.14;
double number = 1.23;

std::cout << number << "\n";
std::cout << (int) number << "\n";


int questions = 10;
int correct = 7;
double grade = correct / questions; // I just noticed that there's operator called "INTEGER DIVISION"
// SOLUTION to use the double version, at least one of the ints must be explicitly casted to a double.
grade = ((double) correct / questions) * 100;

std::cout << "GRADE: " << grade << "%\n" << std::endl;


// IMPLICIT CASTING
int a_number = 21;
char = a_number; //Implicit cast from int to char
std::cout << << "\n";

char wazawaza = 99;
std::cout << wazawaza << "\n";
std::cout << (int) wazawaza << "\n";

int intValue = 5;
float floatValue = 3.14f;
float result = intValue + floatValue; // Implicit cast of intValue to float


return 0;
}

disabledfabrication
Автор

// Implicit (automatic) conversion of double to integer
int locationX = 47.5; // => 47, integer truncates decimal value
std::cout << locationX << std::endl;

// Explicity (manual) conversion of double to integer
double locationY = 40.5; // => 40.5
std::cout << locationY << std::endl;
locationY = (int)locationY; // => 40
std::cout << locationY << std::endl;

// Implicit conversion of double to an character
char letter = locationY;
std::cout << letter << std::endl;

// Explicit converion of an integer to a character
int character = 76;
std::cout << (char)character << std::endl;

// Seeing if you can convert a integer to a character and then
// store the result into a double
double bigBoy = (char)100;
std::cout << bigBoy << std::endl;

// Wondering what happens if you convert a char to a string object...
// doesn't work gives an error about some stuff i don't understand
// wtf it means... moving on...
char firstInitial = 'g';
// std::cout << (std::string)firstInitial << std::endl;

// This code doesn't make sense... Not sure what I was trying
// to do, but whatever I'm out here just trying to understand
// this type conversion stuff
int totalCoins = 25;
int bonusMultiplier = 5;
int totalPoints = 2576;
// If I didn't convert totalCoins to a double the result would of truncated
// the decimal part do to integer division
double finalScore = totalPoints / (double) totalCoins * bonusMultiplier;
std::cout << finalScore << std::endl;

gusgus
Автор

std :: cout << "random comment" << std :: endl;

anvrag