Sorting an array of integers in C++
First thing first, make it into a function, such that your main will be
int main(){
    const int siz = 6;
    int arr[siz] = {4,6,3,1,3,8};

    std::cout &lt;&lt; &quot;Before sort\n&quot;;
    printarr(arr,siz);

    sort(arr, siz);

    std::cout &lt;&lt; &quot;After sort\n&quot;;
    printarr(arr,siz);
}


Since you've tagged it c++, do not use c-style array. Use std::vector. Use std::swap. Currently, it is plain old c. Nothing wrong with it, except the tag.

Optimization wise, well, bubble sort does not deserve it.