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
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
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
   // 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
  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
#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
#53 C++ +7
int chromosome::getScore()
{
    return this->getScore();
}
By Anonymous, 2015-11-05 15:41:39
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
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
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
if(!strncmp(pcTagName,strlim,(int)strlen(strlim))) return "";
By Anonymous, 2021-06-08 19:32:50
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
    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