what is the difference between 'a' and "a" in C++ ???
Answers
Answered by
1
Explanation:
charecter and string hope it helps have a
Answered by
1
'a' is a character.
"a" is a String.
Anything written in single inverted commas is accepted as a character. & mentioned in double inverted commas is accepted as a String.
This is the major difference between 'a' & "a" in C++.
- 'a' is a character literal. It's of type char, with the value 97 on most systems (the ASCII/Latin-1/Unicode encoding for the letter a).
- "a" is a string literal. It is of the type const char[2], and refers to an array of 2 chars with values 'a' and '\0'. In most, but not all, contexts, a reference to "a" will be implicitly converted to a pointer to the first character of the string.
Both
cout << 'a';
cout << "a";
- Happen to produce same output, but for the different reasons. The first prints a single character value.
- The second successively prints all characters of a string (except for the terminating '\0') -- which happens to be a single character 'a'.
- String of the literals can be arbitrarily long, such as "abcdefg". Character literals almost always contain just the single character.
Hence, The difference is: 'a' is a character & "a" is a String.
#SPJ2
Similar questions