Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By looking at your code I am assuming that you are trying to build a static array, so I will demonstrate that (so you don't have to focus on concepts like malloc for the time being). There is however, several problems with your code that I will go over now.</p> <p>First off your array declaration:</p> <pre><code>char A[]; </code></pre> <p>to me it looks like your for loop is filling an array of integers, so this array should be declared as an integer, furthermore you are not setting the size of the array, since your code has i increment until it is 1000 you should just declare an integer array with 1000 elements:</p> <pre><code>int A[1000]; </code></pre> <p>Second your for loop:</p> <pre><code>for(int i = 0, int i = 1000; i++) </code></pre> <p>you're better off just declaring <code>i</code> with the rest of your variables, although you can declare it in a for loop I personally wouldn't suggest doing it. Also you declare <code>i</code> twice in this loop. Finally your condition to continue the loop (<code>i = 1000</code>) will abort the loop immediatly since <code>i</code> will never be equal to <code>1000</code> since you set it to <code>0</code>. Remember a for loop only loops while the middle statement is true. So with that in mind you should now have:</p> <pre><code>int A[1000], i, x, y = 5; for(i = 0; i &lt; 1000; i++) </code></pre> <p>And now we can use the <code>=</code> statement and the value of <code>i</code> to set each array element for <code>A</code>:</p> <pre><code>int A[1000], i, x, y = 5; for(i = 0; i &lt; 1000; i++) { x += y; A[i] = x; } </code></pre> <p>it's that simple!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload