Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 331609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:47:25+00:00 2026-05-12T09:47:25+00:00

From The C Programming Language (Brian W. Kernighan), 2.7 TYPE CONVERSIONS, pg 43 :

  • 0

From The C Programming Language (Brian W. Kernighan), 2.7 TYPE CONVERSIONS, pg 43 :

“There is one subtle point about the
conversion of characters to integers.
… On some macines a char whose
leftmost bit is 1 will be converted to
a negative integer. On others, … is
always positive. For portability,
specify signed or unsigned if
non-character data is to be stored in
char variables.”

My questions are:

  1. Why would anyone want to store
    non-char data in char? (an example
    where this is necessary will be real
    nice)

  2. Why does integer value of char
    change when it is converted to int?

  3. Can you elaborate more on this
    portability issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:47:25+00:00Added an answer on May 12, 2026 at 9:47 am

    In regards to 1)

    People often use char arrays when they really want a byte buffer for a data stream. Its not great practice, but plenty of projects do it, and if you’re careful, no real harm is done. There are probably other times as well.

    In regards to 2)

    Signed integers are often sign extended when they are moved from a smaller data type. Thus
    11111111b (-1 in base 10) becomes 11111111 11111111 11111111 11111111 when expanded to 32 bits. However, if the char was intended to be unsigned +255, then the signed integer may end up being -1.

    About portability 3)

    Some machines regard chars as signed integers, while others interpret them as unsigned. It could also vary based on compiler implementation. Most of the time you don’t have to worry about it. Kernighan is just trying to help you understand the details.


    Edit

    I know this is a dead issue, but you can use the following code to check if char’s on your system are signed or unsigned:

    #include <limits.h> //Include implementation specific constants (MAX_INT, et c.)
    #if CHAR_MAX == SCHAR_MAX 
    // Plain "char" is signed
    #else
    // Plain "char" is unsigned
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 215k
  • Answers 215k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I didn't really ever get around to solving this question,… May 12, 2026 at 10:56 pm
  • Editorial Team
    Editorial Team added an answer I think what you want is the Factory Design Pattern. May 12, 2026 at 10:56 pm
  • Editorial Team
    Editorial Team added an answer You need to convert a character, such as 'a', into… May 12, 2026 at 10:56 pm

Related Questions

I was greeted with a nasty bug today. The task is pretty trivial, all
This is a question for anyone who has the pleasure to work in both
From The C Programming Language 2nd Edition: Since an argument of a function call
I'm reading The C Programming Language (2nd ed.) and near the beginning, it has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.