Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why am getting strange output "÷" when performing the simple follwoing c++ lines

When running this code:

#include <iostream>
using namespace std;

int main() {
    // Signed char
    signed char signedCharValue = -10;
    cout << "Signed char: " << signedCharValue << endl;

    // Unsigned char
    unsigned char unsignedCharValue = 246;
    cout << "Unsigned char: " << unsignedCharValue << endl;

    return 0;
}


i’m expecting:

Signed char: -10
Unsigned char: 246

i’m getting:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Signed char: ÷
Unsigned char: ÷

>Solution :

It’s because this is C++, not C.

char is a distinct type, and the << operator that is used for the output has an overload for char, to output it as such.

If you want the codes, cast it to int.

cout << "Signed char: " << (int)signedCharValue << endl;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading