/*1*/ const char *const letter = 'A'; /*2*/ const char *const letter = "Stack Overflow";
Why is 1 invalid but 2 valid?
a letter is a pointer to which an address must be assigned. Are quoted strings addresses? I assume that is why No. 2 is valid and that single quotes are not considered addresses?
Also, what is the difference between these two types of casting ?:
static_cast<>and ().
static_cast<>
()
And finally, if var is a char variable, why does cout <& var <go outside? Why should I use it for void *?
Thank you for your patience with the newbies.
'A' , a char, 65 41 16, - ASCII.
'A'
char
"Stack", , , {'S', 't', 'a', 'c', 'k', '\0'}, .
"Stack"
{'S', 't', 'a', 'c', 'k', '\0'}
" static_cast ()" , , .
static_cast
, char var = 'x'; cout << &var ..., , &var - char *, , - cout nul \0 , . :
char var = 'x'; cout << &var ...
&var
char *
cout
\0
#include <iostream> int main() { //int q1 = 0; char xx = 'x'; //int q2 = 0; std::cout << &xx << std::endl; return 0; }
:
x~Í"
q, , , x ). , C, - , . .
q
x
- char, A. , char..
A
array of characters , , .
array of characters
char letter [] = { 'H', 'e', 'l', 'l', 'o', '\0' }; char letter [] = "Hello";
letter.
letter
.
"A" - (, "65" ). , C - , , . , , , , "" , 65.., , , , .
, ( "A" ), , . - , , , , , , .
, static_cast () (type) , static_cast < > () , ( ). (, const_cast (value), () , .
char ( int, ), , char l = 'A';, ASCII A l.
int
char l = 'A';
l
char* letters = "foo",
char* letters = "foo"
char letters[4]; letters[0] = 'f'; ... letters[3] = '\0';
One of the ways that I usually follow is to use the typeid operator to understand the types I'm dealing with.
Thoug type_info :: name returns the string defined by the implementation, usually it is quietly explanatory many times in order to understand what we are dealing with. The output below is shown when compiling with gcc
#include <iostream> #include <typeinfo> using namespace std; int main(){ cout << typeid('A').name() << endl; // prints 'c' meaning char cout << typeid("Stack Overflow").name() << endl; // prints 'A15_c' meaning // array of 15 characters }
Source: https://habr.com/ru/post/1760688/More articles:Ruby Custom Logging Rules - ruby | fooobar.comИзвлечение данных из вложенных таблиц в PDF - c#Oracle decoding function - oracleJQuery animation when another animation runs - jqueryShell variable misinterpreted in awk - awkCapturing an image as an array using Python OpenCV - pythonFile I / O in the programming language D - dAutomatically refresh an ASP.NET web page after a certain interval? - asp.netHow to find character code in PL / SQL? - sqlSpring, Hibernate multiple sleep configuration - javaAll Articles