<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Why my below statement throw error  ?]]></title><description><![CDATA[<p dir="auto">I have question regarding  below statement</p>
<p dir="auto">record[0].name[30] ="mangal";</p>
<p dir="auto">when i use it in below code it throw error. i want to know technical reason behind that .</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
struct student{
    int id;
    char name[30];
    float percentage;
};
int main(){
    int i;
    struct student record[2];
    // 1st student's record
    record[0].id=1;
    record[0].name[30] ="mangal";
   // strcpy(record[0].name, "Bhanu");
</code></pre>
]]></description><link>https://forum.qt.io/topic/136403/why-my-below-statement-throw-error</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 14:44:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/136403.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 May 2022 09:29:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 12:13:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/713544">Why my below statement throw error ?</a>:</p>
<blockquote>
<p dir="auto">It's not that which I was drawing attention to.  I am expecting OP to get a compiler error message:</p>
</blockquote>
<p dir="auto">Yes, I also saw this, but this is one of many error in this code extract:</p>
<ul>
<li>index out of bounds</li>
<li>bad types</li>
<li>wrong assignment statement</li>
<li>...</li>
</ul>
<p dir="auto">Impressive how many errors can be done in less than 100 lines of code :D</p>
]]></description><link>https://forum.qt.io/post/713545</link><guid isPermaLink="true">https://forum.qt.io/post/713545</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Tue, 10 May 2022 12:13:19 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 12:08:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> said in <a href="/post/713531">Why my below statement throw error ?</a>:</p>
<blockquote>
<p dir="auto">And in your code you are trying update item 31 of  name  and you are surprise that this do not work!!</p>
</blockquote>
<p dir="auto">It's not that which I was drawing attention to.  I am expecting OP to get a <em>compiler</em> error message:</p>
<pre><code>struct student{
    char name[30];
}
record[0].name[30] ="mangal";
</code></pre>
<p dir="auto">The <em>type</em> of <code>name[30]</code> versus the <em>type</em> of <code>"..."</code>.</p>
]]></description><link>https://forum.qt.io/post/713544</link><guid isPermaLink="true">https://forum.qt.io/post/713544</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 10 May 2022 12:08:04 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 10:31:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a> said in <a href="/post/713514">Why my below statement throw error ?</a>:</p>
<blockquote>
<p dir="auto">But i not know why ?</p>
</blockquote>
<p dir="auto">Are you understanding what you are coding?<br />
You have defined a struct which constains an int value called <code>id</code>, a float value call <code>percentage</code> and an array of char called <code>name</code> which have 30 elements.</p>
<p dir="auto"><strong>And in your code you are trying update item 31 of  <code>name</code>  and you are surprise that this do not work!!</strong></p>
<p dir="auto">Are you serious?</p>
]]></description><link>https://forum.qt.io/post/713531</link><guid isPermaLink="true">https://forum.qt.io/post/713531</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Tue, 10 May 2022 10:31:43 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 10:03:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a> said in <a href="/post/713514">Why my below statement throw error ?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> error is telling me assignment is not possible. But i not know why ?</p>
</blockquote>
<p dir="auto">For goodness sake, that is not an <em>error message</em>....  Really how do you expect people to help you?</p>
]]></description><link>https://forum.qt.io/post/713527</link><guid isPermaLink="true">https://forum.qt.io/post/713527</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 10 May 2022 10:03:23 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 09:55:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a> Why don't you use QString instead of char array?<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/lacuna">@<bdi>lacuna</bdi></a> explained you why you get that error (you need to understand that you can't assign to an array like you do).</p>
]]></description><link>https://forum.qt.io/post/713524</link><guid isPermaLink="true">https://forum.qt.io/post/713524</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 10 May 2022 09:55:14 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 09:52:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a><br />
<em>Your error might be this:<br />
error: array type 'char [30]' is not assignable</em></p>
<p dir="auto">You just can't do "record[0].name[30] ="mangal";"<br />
As the contents are modifiable, the arrays themselves are not.<br />
Use strcpy from &lt;string.h&gt; instead.</p>
<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;iostream&gt;

struct student{
    int id;
    char name[30];
    float percentage;
};

int main(){
    
    int i;
    
    struct student record[2];
    
    // 1st student's record
    record[0].id=1;
    strcpy(record[0].name,"mangal");
    
    // 2st student's record
    record[1].id=2;
    strcpy(record[1].name,"himanshu");
    
    //test
    std::cout &lt;&lt; record[0].name &lt;&lt; std::endl;
    std::cout &lt;&lt; record[1].name &lt;&lt; std::endl;
}
</code></pre>
<p dir="auto">Just one hint - I would do the "record = id"  ;-) its easier to handle.</p>
]]></description><link>https://forum.qt.io/post/713522</link><guid isPermaLink="true">https://forum.qt.io/post/713522</guid><dc:creator><![CDATA[lacuna]]></dc:creator><pubDate>Tue, 10 May 2022 09:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 09:43:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a> PLEASE post the whole error!<br />
And PLEASE also answer <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> question!<br />
Help others to help you, do not make it unnecessary difficult to help you!</p>
]]></description><link>https://forum.qt.io/post/713519</link><guid isPermaLink="true">https://forum.qt.io/post/713519</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 10 May 2022 09:43:58 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 09:35:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> error is telling me assignment is not possible. But i not know why ?</p>
]]></description><link>https://forum.qt.io/post/713514</link><guid isPermaLink="true">https://forum.qt.io/post/713514</guid><dc:creator><![CDATA[Qt embedded developer]]></dc:creator><pubDate>Tue, 10 May 2022 09:35:26 GMT</pubDate></item><item><title><![CDATA[Reply to Why my below statement throw error  ? on Tue, 10 May 2022 09:33:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qt-embedded-developer">@<bdi>Qt-embedded-developer</bdi></a> said in <a href="/post/713511">Why my below statement throw error ?</a>:</p>
<blockquote>
<p dir="auto">when i use it in below code it throw error. i want to know technical reason behind that .</p>
</blockquote>
<p dir="auto">Seriously?  Do you think posting the error message you are receiving from the compiler would be relevant, or should we guess?</p>
<blockquote>
<p dir="auto"><code>record[0].name[30] ="mangal";</code></p>
</blockquote>
<p dir="auto">The most basic C/C++.  What type is <code>record[0].name[30]</code>?  I'm quite sure whatever error message you are receiving tells you this....</p>
]]></description><link>https://forum.qt.io/post/713513</link><guid isPermaLink="true">https://forum.qt.io/post/713513</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 10 May 2022 09:33:25 GMT</pubDate></item></channel></rss>