Enabling stack overflow protection with Y/N prompt This asks the user if they would like to enable stack overflow protection. If they enter yes (Y or y), then a Boolean SOProtection is set to true. If they enter no (N or n), then SOProtection is set to false.

If neither Y, y, N nor n is entered, then it clears the input stream (to protect against a case where multiple characters are entered, which results in the input being run through multiple times).

How can this code be optimized (in both efficiency and performance)?

bool SOProtection;
char checkSOProtection;

while(true){
    std::cout &lt;&lt; "Stack overflow protection? Y/N: ";
    std::cin &gt;&gt; checkSOProtection;

    if(checkSOProtection == 'Y' || checkSOProtection == 'y'){
        SOProtection = true;
        break;
    }

    if(checkSOProtection == 'N' || checkSOProtection == 'n'){
        std::cout &lt;&lt; "Warning: If large values are entered, segmentation fault will occur!" &lt;&lt; std::endl;
        SOProtection = false;
        break;
    }
    std::cin.clear();
    std::cin.ignore(std::numeric_limits&lt;char&gt;::digits10);
}
Your ignore can produce some erratic results, depending upon the number of characters entered by the user.  Rather than:

std::cin.ignore(std::numeric_limits&lt;char&gt;::digits10);


You might want to go with:

std::cin.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');


Which will ignore all of the entered characters up to the end of the input line.  That way you don't start going round the loop multiple times, or with left over characters if the user enters:


  asdfasdfasdfasdfasdf


I'd also consider moving the warning to before the question.  Telling me there may be a seg fault after I've already selected that route seems like a waste of time.  I'd prefer to have that information prompted before I select Y/N (or given the question have it assume that I already know that information).