How does the Serial monitor display '12594' when we write Serial.print('12');?I have used single quotes intentionally.
[code]
void setup()
{
Serial.begin(9600);
Serial.print('12');
}
void loop()
{
}
[/code]
How does the Serial monitor display '12594' when we write Serial.print('12');?I have used single quotes intentionally.
[code]
void setup()
{
Serial.begin(9600);
Serial.print('12');
}
void loop()
{
}
[/code]
Why are you using single quotes?
If we write Serial.print('6'); then its ASCII value get printed.I wanted to see what happens when we write Serial.print('12');.........You may even try Serial.print('10'); or Serial.print('11');
The values in that case comes out t o be '12592' and '12593' respectively.So I want to know what is actually happening
Single quotes are typically used to declare character constants (that means only on character is permitted within the quotes).
The compiler should give you warning if you try to include more than one character.
sketch_dec17a.ino:4:14: warning: multi-character character constant [-Wmultichar]
In practice, what you are seeing is down to either of the following:
The value of 'ab' is likely to be either 'a' * 256 + 'b'
or 'b' * 256 + 'a'. It will vary from one compiler to another.
In his case (where ASCII 1=49 and ASCII 2=50 you are likely seeing:
(49*256)+50 = 12594
according to C99 this is implementation specefic so for the Arduino compiler it apears to be interpreting the character literal as an int which is perfectly valid
go figure
lol, were on it at the same time