Signed and unsigned integer in C++ language by R4R Team

Basically, in numbers data_type like integer we have some range of 'int' in both side of 0, i.e., negative as well as positive.
or,
we store negative as well as positive value in integer type variable.

signed variable:
In signed data_type we also have capability to store negative values.
-By default when we declared any data_type then it is signed

unsigned variable:
In unsigned variable data_type we only store positive values(including 0).
-Or when we want to store only positive value in that case we use unsigned integer.

Example-
unsigned int age;
-Because age can't be negative.

Syntax-
unsigned data_type variable_name;

program:

#include < iostream>
using namespace std;
int main()
{
unsigned int age;
cout<<"Enter agen";
cin>>age;
cout<<"Age is: "<< age;
return 0;
}


output-

Enter age
23
Age is: 23

-In this program, if we enter some negative value then it will give an error.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!