0

Variables

Whenever I declare a variable of data type int in c++. And assign value in such way int a='65'. It gives me some irrelevant output. Why is it so??

27th Oct 2018, 7:11 AM
shahzad
shahzad - avatar
7 Answers
+ 3
just try : int a =65;
27th Oct 2018, 7:18 AM
Vashishtha Upadhyay
Vashishtha Upadhyay - avatar
+ 2
because you can only write one character inside single quote ( ' ) but when you try to write more than one character the compiler will misinterprete that.
27th Oct 2018, 9:04 AM
Tanay
Tanay - avatar
+ 1
int a = 65; // don't forget the ; at end of line then it must be good, or you can do: int a; a = 65; if you do as above and still get irrelevant output then maybe something else is wrong, please show then your code.
27th Oct 2018, 7:25 AM
uther pendragon
uther pendragon - avatar
0
I know I miss Semicolon at end. I left it willingly here. I know it is done when I write a=65. but my Question is why it shows irrelevant answer when I place a='65'
27th Oct 2018, 8:41 AM
shahzad
shahzad - avatar
0
Because '65' means two characters, six is a character and five is a character. and with single quotes you only can use one character. a = 'A'; is same as a = 65; but a = '65'; means error. everything you use between ' ', you must see it as a character.
27th Oct 2018, 9:22 AM
uther pendragon
uther pendragon - avatar
0
Hi
1st Mar 2020, 10:24 PM
Confidence Umeh
Confidence Umeh - avatar
0
It will bring out that irrelevant output because their isn't a space between a and an equal sign
22nd Mar 2021, 6:48 PM
Steven