string sum_numbers(string a, string b) {
        char ca, cb, ci, out, co = '0';
        string result = "";
        while (a.size() > 0 || b.size() > 0 || co != '0') {
            ci = co; ca = '0'; cb = '0';
            if (a.size() > 0) {ca = a.back(); a.pop_back();}
            if (b.size() > 0) {cb = b.back(); b.pop_back();}
            result = ((((ca != cb) ? '1' : '0') != ci) ? '1' : '0') + result;
            co = ((((ca == '1' && cb == '1') ? '1' : '0') == '1' || 
                 ((((ca != cb) ? '1' : '0') == '1' && ci == '1') ? '1' : '0') == '1') ? '1' : '0');
        }
        return result;
    }

Scary stuff

By Anonymous, 2023-12-01 22:20:27
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>

constexpr int N = 10;

int main() {
    std::vector<int> even;
    std::vector<int> odd;
    
    even.resize(N);
    
    // Fill up the 'even' vector with integers starting from from 1 through 'N'
    std::iota(even.begin(), even.end(), 1);

    // Segregate the odd and even integers from each other
    
    for (auto it = even.begin(); it != even.end(); ++it)
        if (*it % 2 != 0) {
            // If the number is odd, put it in the 'odd' vector
            odd.push_back(*it);
            // Remove the number from the even vector
            even.erase(it);
        }

    // Print the result
    
    std::cout << "Even numbers: ";
    std::copy(even.begin(), even.end(), std::ostream_iterator<int>(std::cout, " "));

    std::cout << "\nOdd numbers: ";
    std::copy(odd.begin(), odd.end(), std::ostream_iterator<int>(std::cout, " "));

    std::cout << '\n';
}

Seems fine to me... C++ couldn't possibly be THAT evil to introduce another nuanced and verbose complexity in there, right?

By cufbox, 2023-12-15 09:38:58
int var = 0;
int* ptr = &var;
ptr[0] = 5;
std::cout << ptr[0];
By Anonymous, 2015-07-24 23:51:35
int main() {
    int error_code = some_function();
    if (error_code == 1) {
        // In case of error, crash the program by eating up memory
        while (true) new int;
    }
}
By Anonymous, 2024-04-30 08:31:39
void winner(int score[4])
{
    
    if (score[0] > score[1] > score[2] > score[3])
        cout << "The winner is the Player 1 with " << score[0] << " points.";
    else if (score[1] > score[0] > score[2] > score[3])
        cout << "The winner is the Player 2 with " << score[1] << " points.";
    else if (score[2] > score[0] > score[1] > score[3])
        cout << "The winner is the Player 3 with " << score[2] << " points.";
    else if (score[3] > score[2] > score[1] > score[0])
        cout << "The winner is the Player 4 with " << score[3] << " points.";
}
By Anonymous, 2020-05-17 16:06:24
  if(!Hardware::initialize()) {
    Serial.println("Hardware initialization failed!");
    for(;;){}
  }

  if(!UI.begin()) {
    Serial.println("SSD1306 allocation failed");
    for(;;){}
  }

For is best ever, why even bother with While, or even Return... Source of code: https://github.com/MausTec/nogasm-wifi/blob/master/ESP32_WiFi.ino

By Anonymous, 2020-11-22 20:05:34
if(!strncmp(pcTagName,strlim,(int)strlen(strlim))) return "";
By Anonymous, 2021-06-08 19:32:50
if ((&inactiveSlot)->GetFirstSlot() == RuntimeLib::INVALID_SLOT) {

Dot dude...

By 314, 2020-05-07 10:56:22
auto settingsFileSize = static_cast<int>(sizeof(_settings));

This was in release branch for a month. Casting wasn't even necessary.

By Your favourite co-worker., 2019-06-04 09:05:15
void MagicUnit::getSomeVoltage(std::uint64_t w_data, double &val)
{
    std::uint64_t r_data = 0;
    hwRead((int)Address::Voltage, 3, w_data, 2, &r_data);
    val = r_data;
    val /= 16; // shit right 4 bits
    val *= 0.004;
    val -= 8.192;
}
By Anonymous, 2019-03-11 08:43:52
  ierr = pxmlIn->GetData(pcTag, *pTData);
  *pbDataValid = bool((ierr==0)&&(iLen>0));  // enabled if: not empty string and vaild (number?)
  if (*pbDataValid)  iErr += ierr;
By Anonymous, 2020-04-07 14:44:12
double zuida(std::vector<double> vec) {
	std::vector<double> temp;
	for(int i = 0; i < vec.size(); i++)
		temp.push_back(vec[i]);
notend:
	if(temp.size() > 0) {
		if(temp.size() < 2) {
			double tmp = *(&temp[0]);
			return tmp;
		}
		else if(temp.size() >= 2) {
			double mini = temp[0];
			int ind = 0;
			for(int i = 0; i < temp.size(); i++)
				if(temp[i] < mini) {
					mini = temp[i];
					ind = i;
				}
			temp.erase(temp.begin() + ind);
			goto notend;
		}
	}
}

The beauty is that every case is the best (also worst) case!

By Anonymous, 2019-10-12 10:42:23
#53 C++ +13
int chromosome::getScore()
{
    return this->getScore();
}
By Anonymous, 2015-11-05 15:41:39
for (int i = 0;i < n / 2;i++)
    {
        while (num[a[p].id].n == 0 || num[num[a[p].id].nxt].n == 0)
        {
            p++;
        }
        printf("%d %d ", num[a[p].id].n, num[num[a[p].id].nxt].n);
        num[a[p].id].n = 0;
        num[num[a[p].id].nxt].n = 0;
        num[num[a[p].id].lst].nxt = num[num[a[p].id].nxt].nxt;
        num[num[num[a[p].id].nxt].nxt].lst = num[a[p].id].lst;
    }
By Anonymous, 2022-08-06 14:50:56
 void SummonCrowd()
        {
            if(!bSummoned1)
            {
                if (Creature* Witness1 = me->SummonCreature(NPC_LISTENER,-11009.036f, 1490.47f, 43.58f, 4.16f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                    if (Creature* Witness2 = me->SummonCreature(NPC_LISTENER,-11010.76f, 1488.21f, 43.57f, 4.33f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                        if (Creature* Witness3 = me->SummonCreature(NPC_LISTENER,-11017.39f, 1491.76f, 43.19f, 4.78f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                            if (Creature* Witness4 = me->SummonCreature(NPC_LISTENER,-11021.73f, 1493.054f, 43.184f, 5.09f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                if (Creature* Witness5 = me->SummonCreature(NPC_LISTENER,-11025.74f, 1487.70f, 43.17f, 5.45f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                    if (Creature* Witness6 = me->SummonCreature(NPC_LISTENER,-11025.25f, 1482.23f, 43.03f, 6.04f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                        if (Creature* Witness7 = me->SummonCreature(NPC_LISTENER,-11029.68f, 1481.255f, 43.185f, 6.20f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                            if (Creature* Witness8 = me->SummonCreature(NPC_LISTENER,-11024.46f, 1473.88f, 43.02f, 0.43f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                if (Creature* Witness9 = me->SummonCreature(NPC_LISTENER,-11019.49f, 1471.70f, 43.21f, 1.09f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                    if (Creature* Witness10 = me->SummonCreature(NPC_LISTENER,-11021.56f, 1497.053f, 43.20f, 5.00f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                        if (Creature* Witness11 = me->SummonCreature(NPC_LISTENER,-11012.29f, 1488.14f, 43.77f, 4.16f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                            if (Creature* Witness12 = me->SummonCreature(NPC_LISTENER,-11014.67f, 1493.14f, 43.23f, 4.60f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                if (Creature* Witness13 = me->SummonCreature(NPC_LISTENER,-11019.8f, 1494.25f, 43.2f, 4.77f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                    if (Creature* Witness14 = me->SummonCreature(NPC_LISTENER,-11023.6f, 1489.35f, 43.17f, 4.77f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                        if (Creature* Witness15 = me->SummonCreature(NPC_LISTENER,-11023.1f, 1482.51f, 43.07f, 6.25f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                            if (Creature* Witness16 = me->SummonCreature(NPC_LISTENER,-11027.2f, 1494.37f, 43.17f, 5.15f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                if (Creature* Witness17 = me->SummonCreature(NPC_LISTENER,-11029.6f, 1488.29f, 43.19f, 5.64f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                    if (Creature* Witness18 = me->SummonCreature(NPC_LISTENER,-11030.8f, 1485.13f, 43.31f, 5.94f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                        if (Creature* Witness19 = me->SummonCreature(NPC_LISTENER,-11026.2f, 1478.62f, 42.94f, 6.17f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                            if (Creature* Witness20 = me->SummonCreature(NPC_LISTENER,-11013.2f, 1497.81f, 43.31f, 4.44f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                if (Creature* Witness21 = me->SummonCreature(NPC_LISTENER,-11011.6f, 1492.61f, 43.39f, 4.44f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                    if (Creature* Witness22 = me->SummonCreature(NPC_LISTENER,-11015.4f, 1489.06f, 43.28f, 4.73f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                        if (Creature* Witness23 = me->SummonCreature(NPC_LISTENER,-11020.2f, 1490.15f, 43.19f, 5.07f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                            if (Creature* Witness24 = me->SummonCreature(NPC_LISTENER,-11009.9f, 1483.52f, 44.06f, 3.88f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                                if (Creature* Witness25 = me->SummonCreature(NPC_LISTENER,-11020.1f, 1484.87f, 43.18f, 5.33f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                                    if (Creature* Witness26 = me->SummonCreature(NPC_LISTENER,-11017.7f, 1487.42f, 43.24f, 4.89f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                                        if (Creature* Witness27 = me->SummonCreature(NPC_LISTENER,-11017.9f, 1498.24f, 43.20f, 5.04f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 90000))
                                                                                                                        {
                                                                                                                            Witness1GUID = Witness1->GetGUID();
                                                                                                                            Witness2GUID = Witness2->GetGUID();
                                                                                                                            Witness3GUID = Witness3->GetGUID();
                                                                                                                            Witness4GUID = Witness4->GetGUID();
                                                                                                                            Witness5GUID = Witness5->GetGUID();
                                                                                                                            Witness6GUID = Witness6->GetGUID();
                                                                                                                            Witness7GUID = Witness7->GetGUID();
                                                                                                                            Witness8GUID = Witness8->GetGUID();
                                                                                                                            Witness9GUID = Witness9->GetGUID();
                                                                                                                            Witness10GUID = Witness10->GetGUID();
                                                                                                                            Witness11GUID = Witness11->GetGUID();
                                                                                                                            Witness12GUID = Witness12->GetGUID();
                                                                                                                            Witness13GUID = Witness13->GetGUID();
                                                                                                                            Witness14GUID = Witness14->GetGUID();
                                                                                                                            Witness15GUID = Witness15->GetGUID();
                                                                                                                            Witness16GUID = Witness16->GetGUID();
                                                                                                                            Witness17GUID = Witness17->GetGUID();
                                                                                                                            Witness18GUID = Witness18->GetGUID();
                                                                                                                            Witness19GUID = Witness19->GetGUID();
                                                                                                                            Witness20GUID = Witness20->GetGUID();
                                                                                                                            Witness21GUID = Witness21->GetGUID();
                                                                                                                            Witness22GUID = Witness22->GetGUID();
                                                                                                                            Witness23GUID = Witness23->GetGUID();
                                                                                                                            Witness24GUID = Witness24->GetGUID();
                                                                                                                            Witness25GUID = Witness25->GetGUID();
                                                                                                                            Witness26GUID = Witness26->GetGUID();
                                                                                                                            Witness27GUID = Witness27->GetGUID();

                                                                                                                            bSummoned1 = true;
                                                                                                                        }
            }
        }
By Anonymous, 2020-09-16 17:09:35