user53790: Well I am trying to save phone number as a string. For ease of use I want to add "+" character programmatically. Like this:
String cepNo ="+" + "901234567";

But program gives this error.
exit status 1
invalid operands of types 'const char [2]' and 'const char [13]' to binary 'operator+'

How to add "+" beginning of the string.

user67819: use String cepNo = String("+") + "901234567";
or
String a = "+"; String cepNo = a + "901234567";

user7508: You cannot add C strings (i.e. NUL-terminated arrays of char) with the
+ operator. It only works with String objects. You can, though, add
a String object and a C-string, because in this case the compiler
implicitly converts the C string into a String object:
String phone_number = "901234567";
phone_number = "+" + phone_number;

The last line is interpreted by the compiler as
phone_number = String("+") + phone_number;

That being said, I encourage you to try to avoid String objects if
possible. These use dynamic memory allocation which carries the risk of
heap fragmentation. The same thing can be achieved with plain C strings:
char phone_number[] = "901234567";
char full_phone_number[strlen(phone_number) + 2];
strcpy(full_phone_number, "+");
strcat(full_phone_number, phone_number);

Note the size of the second string: strlen(phone_number) + 2. You need
one extra char for the + sign, and another one for the NUL string
terminator.
Now, with C strings you can do better, and avoid copying: reserve enough
room in an array for the full number (“+” included), and then fill the
digits starting from the second slot in the char array. You can then
add the + sign later:
char phone_number[16];
strcpy(phone_number + 1, "901234567");
phone_number[0] = '+';

Although I personally would write the “+” sign and a NUL while
initializing the array:
char phone_number[16] = "+";
strcat(phone_number, "901234567");


53790: <p>Well I am trying to save phone number as a string. For ease of use I want to add &quot;+&quot; character programmatically. Like this:</p>
<pre><code>String cepNo =&quot;+&quot; + &quot;901234567&quot;;
</code></pre>
<p>But program gives this error.</p>
<pre><code>exit status 1
invalid operands of types 'const char [2]' and 'const char [13]' to binary 'operator+'
</code></pre>
<p>How to add &quot;+&quot; beginning of the string.</p>
 67819: <p>use <code>String cepNo = String(&quot;+&quot;) + &quot;901234567&quot;;</code>
or
<code>String a = &quot;+&quot;; String cepNo = a + &quot;901234567&quot;;</code></p>
 7508: <p>You cannot add C strings (i.e. NUL-terminated arrays of <code>char</code>) with the
<code>+</code> operator. It only works with <code>String</code> objects. You can, though, add
a String object and a C-string, because in this case the compiler
implicitly converts the C string into a String object:</p>
<pre class="lang-cpp prettyprint-override"><code>String phone_number = &quot;901234567&quot;;
phone_number = &quot;+&quot; + phone_number;
</code></pre>
<p>The last line is interpreted by the compiler as</p>
<pre class="lang-cpp prettyprint-override"><code>phone_number = String(&quot;+&quot;) + phone_number;
</code></pre>
<p>That being said, I encourage you to try to avoid String objects if
possible. These use dynamic memory allocation which carries the risk of
heap fragmentation. The same thing can be achieved with plain C strings:</p>
<pre class="lang-cpp prettyprint-override"><code>char phone_number[] = &quot;901234567&quot;;
char full_phone_number[strlen(phone_number) + 2];
strcpy(full_phone_number, &quot;+&quot;);
strcat(full_phone_number, phone_number);
</code></pre>
<p>Note the size of the second string: <code>strlen(phone_number) + 2</code>. You need
one extra <code>char</code> for the <code>+</code> sign, and another one for the NUL string
terminator.</p>
<p>Now, with C strings you can do better, and avoid copying: reserve enough
room in an array for the full number (“+” included), and then fill the
digits starting from the second slot in the <code>char</code> array. You can then
add the <code>+</code> sign later:</p>
<pre class="lang-cpp prettyprint-override"><code>char phone_number[16];
strcpy(phone_number + 1, &quot;901234567&quot;);
phone_number[0] = '+';
</code></pre>
<p>Although I personally would write the “+” sign and a NUL while
initializing the array:</p>
<pre class="lang-cpp prettyprint-override"><code>char phone_number[16] = &quot;+&quot;;
strcat(phone_number, &quot;901234567&quot;);
</code></pre>
