- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are signed and unsigned keywords in C++?
All number types in C++ can either have a sign or not. For example, you can declare an int to only represent positive integers. Unless otherwise specified, all integer data types are signed data types, i.e. they have values which can be positive or negative. The unsigned keyword can be used to declare variables without signs.
Example
#include<iostream> using namespace std; int main() { unsigned int i = -1; int x = i; cout << i << ", " << x; return 0; }
Output
This will give the output −
4294967295, -1
This output is given because it overflows the int by changing all 0 in the bit representation to 1s and max value of int is printed. This is because now the int i doesn't have a sign. But x has a sign so it'll have the value -1 only.
- Related Articles
- Unsigned and Signed Binary Numbers
- Difference between signed and unsigned integer in Arduino
- What are reserved keywords in C#?
- What are contextual keywords in C#?
- How to understand if a bigint is signed or unsigned in MySQL?
- What are Reserved Keywords in Python?
- What are the different types of keywords in C language?
- Variables and Keywords in C
- What is an unsigned char in C++?
- How many keywords are there in C++?
- What Are Keywords Shortcuts for Youtube?
- Are true and false keywords in java?
- Are ‘this’ and ‘super’ keywords in Java?
- Keywords in C#
- What is the difference between keywords const and readonly in C#?

Advertisements