#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
    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
typedef signed int sint;
#define N 100
static int n = N;

inline int f(const int n, int& i, int* j, int t[2], int p=11)
{
    i*=i;
    (*j)--;
    
    if ( n<=0 )
    {
        cout << ::n << ">\n";
        return t[0];
    }
    else return f(n-1, i, j, t) + t[n];
}

int main()
{
    int n = 4;
    int x = 1U;
    sint y = 10;
    int (*fptr)(const int, int&, int*, int*, int) = f;

    int* t = new int[n];
    int& r = *(t+3);
    (*t) = 1;
    *(t+1) = 2;
    t[2] = 3;
    r = 4;

    int z = (*fptr)(5, x, &y, t, 12);    

    for(int i = 0; i < 2*n; i++)
    {
        if( i == n )
            continue;
        if( i > n )
            break;
        cout << t[i] << "\n";
    };
    cout << x << ", " << y << ", " << z << "\n";
    
    delete[] t;
}

This is what my professor gave as part of the final exam. The purpose of giving us this code was to get us used to seeing different ways the C++ syntax can be used and figure out what the output is.

By Anonymous, 2023-02-02 21:29:11
   // Test read access of memory
   try
   {
      c = ( (char*) pvMemory )[0];
      c = ( (char*) pvMemory )[iNLen - 1];
   }

   catch( ... ) {
      return -1;
   }
By Anonymous, 2022-10-19 16:28:05
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
#define private public
#define protected public
#define class struct

#include "your_private_parts.hpp"
// ...

#undef class
#undef protected
#undef private

// ...

Fails miserably if template <class>, template <template <class> class> or their variations are found anywhere inside your header. :(

By 2 + 2 = 3.99999999999999999999999999999999999, 2021-11-08 07:59:05
#include <iostream>
#define OPEN_PARENTHESIS (
#define CLOSE_PARENTHESIS )
#define OPEN_BRACES {
#define CLOSE_BRACES }
#define INTEGER int
#define STANDARD_LIB std::
#define CONSOLE_OUT cout
#define ANGLE_BRACKETS <<
#define MESSAGE "Hello World\n"
#define SEMI ;
#define CLASS_NAME main

INTEGER CLASS_NAME OPEN_PARENTHESIS CLOSE_PARENTHESIS OPEN_BRACES
STANDARD_LIB CONSOLE_OUT ANGLE_BRACKETS MESSAGE SEMI
CLOSE_BRACES

Everything is defined

By Anonymous, 2021-06-28 01:46:44
char *  dataFunc(){
    TCHAR tc[256];
    LONG tc_len = sizeof(tc);
    
    getData((LPBYTE)&tc, &tc_len);
    
    char * data = new char[tc_len];
    for(int i = 0;i < tc_len;i++)
        data[i] = tc[i];
    
    return data;
}
By Hook2, 2021-06-27 15:41:51
if(!strncmp(pcTagName,strlim,(int)strlen(strlim))) return "";
By Anonymous, 2021-06-08 19:32:50
  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
 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
int file_exist(){
    FILE *file;
    if((file = fopen(SCORE_FILE_NAME, "r"))){
        fclose(file);
        return 1;
    }
    return 0;
}
By Anonymous, 2020-06-08 12:01:54
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 ((&inactiveSlot)->GetFirstSlot() == RuntimeLib::INVALID_SLOT) {

Dot dude...

By 314, 2020-05-07 10:56:22
  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