Variables | Sololearn: Learn to code for FREE!

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??

10/27/2018 7:11:01 AM

shahzad

7 Answers

New Answer

+3

just try : int a =65;

+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.

+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.

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'

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.

0

0

It will bring out that irrelevant output because their isn't a space between a and an equal sign