Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

unsigned char

+7 votes
asked Jun 29, 2022 by adnene hlila (190 points)
hello , i dont understande what does mean unsigned char , i know unsigned char only with number  , can some one of you help me please ?

2 Answers

0 votes
answered Jun 30, 2022 by AADI JAIN (350 points)

we know that char  has 8 bits so in a signed char only 7 bits are used for data and 1 is used for  the sign but in unsigned char all 8 bits are used for data and their is no sign bit

#include <stdio.h>

  

int main()

{

  

    int chr = 97;

    unsigned char i = chr;

    printf("unsigned char: %c\n", i);

  

    return 0;

}

Output:

unsigned char: a
commented Jun 30, 2022 by Peter Minarik (86,180 points)
Not quite so. The sign bit is also data.

Your code produces the exact same output if you'd use signed char (for the type of i).
0 votes
answered Jun 30, 2022 by Peter Minarik (86,180 points)
edited Jul 1, 2022 by Peter Minarik

The numeric value of an unsigned char ranges from 0..255.

The numeric value of a signed char ranges from -128..127.

So if you do not wish to store "classic" characters (e.g. 'a', 'b', etc...) in a char, then consider the number you want to store in it, what the maximum and minimum is, would you need to support negative numbers. The default is signed char, if signed/unsigned is not specified.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...