Are signed int and signed will do the same work?

Also can we write
unsigned int b=-9;

//The above statement is not valid naa
as unsigned is used for positive intergers.

This statement was used in ques 5 in quiz 1 on programming fundamentals…

yes this statement is logically not valid
it will not give error
but give unexpected output

question of quiz is not visible to me
can you send the question also
so that i can explain this in context of quiz

I have send u the question of quiz in chat section .
This question uses unsigned for negative integers???

This was the question!

"/* Output ? */
#include<iostream>
using namespace std;

int main(){
    long signed CodingBlocks = 2017;
    short unsigned BOSS1     = -2018;
    unsigned BOSS2           = -2019;
    int      BOSS3           = -2020;
    long long unsigned BOSS4 = -2021;
    short unsigned Nagarro   = 2018.9;
    long signed HackerBlocks = 'A';
    cout<<CodingBlocks<<endl;
    cout<<BOSS1<<endl<<BOSS2<<endl<<BOSS3<<endl<<BOSS4<<endl;
    cout<<Nagarro<<endl;
    cout<<HackerBlocks<<endl;


    return 0;
    }"

2017 2^16 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 65

2017 2018 2019 2020 2021 2018.9 A

2017 2^32 - 2018 2^32 -2019 -2020 2^32 - 2021 2018 65

2017 2^32 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 64

Ans=
2017 2^16 - 2018 2^32 -2019 -2020 2^64 - 2021 2018 65
CodingBlocks is int so int can store 2017

BOSS1 is an unsigned short since unsigned only stores only positive number , so negative numbers are stored as 2^16 - x (where x is negative) (2^16 because short int contain 16 bits)
so -2018 will be stored as 2^16-2018

BOSS2 is an unsigned int and since int has 32bits so the -2020 will be stored as 2^32

BOSS3 is an int so can store -2020

BOSS4 is an unsigned long long int and since long long int has 64 bits so -2021 will be stored as 2^64-2021

Nagarro is an int so 2018.9 will be stored as 2018 (only the integer part)

HackerBlocks is a signed int so ‘A’ will be stored as its ascii value i.e. 65 due to typecasting s

In case of any doubt feel free to ask :slight_smile:
Mark your doubt as RESOLVED if you got the answer