C++Tutorial for Beginners 9 - Integer Variable Types

preview_player
Показать описание
-------------------------------------------------------------------------------------------------------------------------------------------
We'll take a closer look at C++'s integer variable types in this tutorial. Choosing the right size variable for your data is very important in C++, especially since C++ won't necessarily warn you if you choose a type that's too small -- your program just won't work properly!
--------------------------------------------------------------------------------------------------------------------------------------------
Рекомендации по теме
Комментарии
Автор

thanks a lot professor! after these few tutorials I learned how to do this xd:
#include <iostream>
#include <limits>
using namespace std;

int main() {
    string name;
    int age;
    cout<<"what is your name?";
    cin>> name;
    cout<<"How old are you?";
    cin>> age;
    if ((name=="Kevin") &&(age==15)) {
        cout<<"We have the same name and age!";
    }
    else if ((name!="Kevin")||(age!=15))
        cout<<"We are not alike!";

 
}

kupomomo
Автор

Good tutorial, but maybe he should mention the 32bit/64bit issue when explaining the 'long int' and 'int'. I have to use the 'long long int' to store 2345325345345 on my 32b Ubuntu puter..

raylie
Автор

while writing cout << value or uvalue << endl; why did you not write with  " " for example why did you not write cout <<"value" or "uvalue" << endl;       ???

anuragtripathi
Автор

I tried doing long int value2 = 259358737589273; but It only shows the max size of an Int should have... But It was fixed by doing long long int value2 = 259358737589273;... Why is this?! and Why is the LONG_MAX is the same as the INT_MAX?

heatlife
Автор

Excuse me but when I tried to type in INT_MAX n INT_MIN the laptop keep telling me there no such things wonder what did I do wrong? Everything else I tried to follow your example n work just fine it just the INT_MAX & MIN that not being recognized by the workspace.

Never mind turn out just have to switch between #include <limits.h> or #include <climits> to c which 1 work, thank u for the video man :D

tokugeeky
Автор

For both long and short int types, it says: "overflow in implicit constant conversion [-Woverflow]"

SDEliptiK
Автор

I got a compilation error when using the same code as you, using the gcc compiler on Linux. It wouldn't recognize INT_MIN and INT_MAX as defined.

Changing the line #include  <limits> to #include <limits.h> fixed the problem, though I don't really understand why.

frosborg
Автор

I have an error while doing INT_MAX but It was fixed by just doing #include <limits.h> instead of <limits>... Why is this?

heatlife
Автор

When i type INT_MAX and INT_MIN
"was not declared in this scope"

I´m using the exact same software and same code you did in the video. What could be the problem?

yangyangyang
Автор

So you don't need to put "int" when doing like long int = 2526?

heatlife
Автор

sir... nice tutorial but... what abt double int or double..?

silentpredator
Автор

Hey there, can anybody tell me how to use command "limits" on Visual Studio, I mean what exactly to type. I just cannot find that((

nazariiblazhchuk
Автор

Can anyone explain why i get the same value using INT_MAX and LONG_MAX? I'm using visual studio.
2147483647
2147483647

philipsheard
Автор

Clever IDE.
I tried Qt Creator, no response to abnormal interger.

身世成谜
Автор

When I type in "long int lValue = 2323447365368" and start the project, it shows me a complete different number. What do I wrong? (I use Windows 7 and use MinGW GCC as toolchain)
Here is my code:

int main() {

int value = 56458;
cout << value << endl;
cout << INT_MAX << endl; // prints

long int lValue = 2323447365368;
cout << lValue << endl;

short int zValue = 22629;
cout << zValue << endl;
return 0;
}

Cryptorax
Автор

I used long int but it wouldn't give me the exact value I put! It's giving me a warning about overflow...

claramelb
Автор

man do you know how to fix the auto completion it's not working i'm using eclipse and tried look in stack over flow and eclipse forums but none was helpful please tell me if you know

deodorant
Автор

for every one who tried log int and it didnt give the exact value, use long long int

randomshit
Автор

When I type INT_MAX and INT_MIN
"was not declared in this scope"
not understand..plz

mdalaminhossian
Автор

I typed this out:
long int lvalue =
cout << "Long value = " << lvalue << endl;
and the value I got on the console was different. Any ideas what im doing wrong?
I'm using codeblocks.

MRPISSFLAP