Skip to content

Instantly share code, notes, and snippets.

@ohmree
Created May 31, 2017 11:16
Show Gist options
  • Save ohmree/dac78b36b736a71dc9a423d10b9509cc to your computer and use it in GitHub Desktop.
Save ohmree/dac78b36b736a71dc9a423d10b9509cc to your computer and use it in GitHub Desktop.
#include "raylib.h"
void swap(int* num1, int* num2)
{
int temp = 0;
temp = *num2;
*num2 = *num1;
*num1 = temp;
}
int main()
{
int temp = 0;
int arr1[10];
for (int i = 0; i <= 10; i++)
{
arr1[i] = GetRandomValue(0, 1000);
}
for (int i = 0; i <= 10; i++)
{
if (i == 10) break;
if (arr1[i] > arr1[i+1])
{
swap(*arr1[i], *arr1[i + 1]);
}
}
}
@Au-lit
Copy link

Au-lit commented Oct 18, 2021

This code has undefined behavior. You are accessing out of bounds of arr1. (The < operator exists.) And your code doesn’t actually sort anything (if it even compiled).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment