![]() |
|
#1
|
|||
|
|||
Critical Declaration questionCPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Critical Declaration quesitonQuote:
CPP / C++ / C Code:
Code:
What happens when a 1-byte char value is assigned to a 4-byte int? Since ASCII values typically are 7-bits, the most significant bit is set to zero. When assigned to an int, the three most significant bytes of the int are also set to zero. |
|
#3
|
|||
|
|||
Re: Critical Declaration questionMy question is not that, I want to ask, why varialbe declared as character accept integer and display the integer, and why not the variable declared as integer is does not display the character.
|
|
#4
|
|||
|
|||
Re: Critical Declaration questionQuote:
As long as it is a character, it will display the character. Integer is not allow to store character but you can display it ANSII value. |
|
#5
|
|||
|
|||
Re: Critical Declaration questionA variable of type character allows you to assign chars and numbers (like integer, float, etc...). However, you can´t use a variable of type char (even if it was assigned a number) to make calculations.
I hope this help you. |
|
#6
|
|||
|
|||
Re: Critical Declaration questionQuote:
Actually, Peter_APIIT is right. Everything is stored as a numerical value. In the case of chars, the value is interpreted as an ASCII character, & if printable, the corresponding character glyph will be displayed. If the numeric value represents an unprintable ASCII character, nothing should be displayed. |
|
#7
|
|||
|
|||
Re: Critical Declaration questionyou can assign a number to char because numbers also have an ascii values and they can be considered as just plain characters which does not have any other functionalities of numbers.
But you obviously cannot masquerade a charater as a number because a number is as a subset of chars with many special features which other chars dont have. so this is expected to throw an error. |
|
#8
|
|||
|
|||
Re: Critical Declaration questionQuote:
eg: enter any alphabet when it ask for a number and it will break the normal execution. (Atleast if you are using vc++ 2008 ) run this again and enter a number when it asks for a number and enter a number again when it asks for a char. There is no problem in this case. CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
Re: Critical Declaration questionyou might want to use this code if you want to handle this issue.
CPP / C++ / C Code:
(check this out: http://www.parashift.com/c++-faq-lit....html#faq-15.3) |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| run script command on ns2.26 | newbie06 | Computer Software Forum - Linux | 65 | 19-Aug-2009 08:50 |
| Error C2374 | lolp1 | C++ Forum | 3 | 25-May-2008 17:40 |
| Multiple questions for C++ project | devster420 | C++ Forum | 1 | 20-Apr-2007 22:26 |
| Implicit Declaration error | mike3340 | C++ Forum | 1 | 16-Dec-2003 09:12 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The