LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2011, 11:28 PM   #1
manohar
Member
 
Registered: Dec 2010
Posts: 42

Rep: Reputation: 2
Smile char variable is behaving as unsigned char


Hi,

i define variable of type char (range -128 to 127). when i tried to print the value after assigning a -ve value to it it displaying a +ve value of that -ve value(256+value).
 
Old 02-14-2011, 11:43 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Platform, language, compiler, ... ?



Cheers,
Tink
 
Old 02-14-2011, 11:54 PM   #3
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Anything like this you are trying to do? This gives me -125 as expected!
Code:
#include <stdio.h>

int main ()
{
     char c;
     
     c = -125;
     printf ("%d\n", c);
     
     return 0;
}
 
Old 02-15-2011, 12:19 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
char doesn't have to be signed by default. What happens when you use signed char?
Kevin Barry
 
1 members found this post helpful.
  


Reply

Tags
[c]



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
i need to convert a char * to unsigned char anurupr Programming 5 03-04-2010 02:55 PM
difference between char and unsigned char..?? sumitshining Programming 8 11-17-2008 08:08 PM
conversion from ‘const char*’ to ‘unsigned char*’ rubadub Programming 2 02-08-2008 05:45 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 04:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration