JdBP>> char ch ;
JdBP>> char str[2] = { ch } ;
TH> Not at initilation time, at runtime
I don't understand your objection. My only guess is that you aren't familiar
with this particular part of the C++ language, and are erroneously assuming
that objects with automatic storage duration are initialised at program
startup. They are not.
The semantics of Standard C++ *require* that automatic storage objects be
initialised every time that execution passes through the statement. In this
case, str[] is initialised with the current value of `ch' and a zero.
This idiom is a very useful shorthand for those occasions where otherwise one
would, as you did, follow an array or structure declaration of automatic
storage with a succession of assignment statements.
See sections 8.5 and 8.5.1 (especially paragraph 7) of the C++ Standard.
¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)
|