Deal with segmentation fault : <p>I am trying to solve a CodeChef problem. Whenever I run it I get a segmentation fault. This is the link to the problem: <a href="https://www.codechef.com/problems/CHN09" rel="nofollow">Malvika is peculiar about color of balloons</a></p>

<p>Here is my code :</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;cstring&gt;
#include&lt;algorithm&gt;

int main(){
    std::string balloonColors;
    size_t numberOfAmber;
    size_t numberOfBrass;
    int t;
    int results[t];

    std::cin &gt;&gt; t;

    for (int i = 0; i &lt; t; i++){
        int result = 0;
        std::cin &gt;&gt; balloonColors;
        numberOfAmber = std::count(balloonColors.begin(), balloonColors.end(), 'a');
        numberOfBrass = std::count(balloonColors.begin(), balloonColors.end(), 'b');

        if (numberOfAmber == 0 || numberOfBrass == 0){
            result = 0;
        }

        if (numberOfAmber &lt;= numberOfBrass){
            result = (int)numberOfAmber;
        }
        else {
            result = (int)numberOfBrass;    
        }

        results[i] = result;

    }
    for (int x = 0; x &lt; t; x++){
        std::cout &lt;&lt; results[x] &lt;&lt; std::endl;
    }
}
</code></pre>
