Welcome to Incels.is - Involuntary Celibate Forum

Welcome! This is a forum for involuntary celibates: people who lack a significant other. Are you lonely and wish you had someone in your life? You're not alone! Join our forum and talk to people just like you.

It's Over teaching myself how to program again

Programming is pretty cool.
If you save a Notepad file as .exe instead of .txt you can start making something.
 
practicing on passing a pointer that accesses a vectorized array in main() from the void function and using it to swap two variables

Code:
#include <iostream>
#include <vector>
using namespace std;

//assignment: make a vectorized array in main(), make a function that passes a pointer var and two integer vars
//in which you'll use to swap two elements ( element no.2 and element no.4) in the vectorized array


void swapper (vector<int> *ptr, int x, int y)
{

    int temp       = (*ptr)[x];
    (*ptr)[x]      = (*ptr)[y];
    (*ptr)[y]      = temp;




}

int main(int argc, char** argv) {

//vectorized init and input
int max2;
   
cout << "hey ! welcome to svg's vectorized array pointer swapper" << endl;
cout << "enter your array's size number or the maximum number of numbers in array" << endl;
cin >> max2;

vector<int> ar2(max2);

for (int b = 0; b < max2; b++) {
    cout << "enter element number " << b << ": ";
    cin >> ar2[b];
}

vector<int> *ptr1 = &ar2;


int x = 2;
int y = 4;


swapper (ptr1, x, y);



for (int b = 0; b < max2; b++) {
    cout << "element number " << b << " is " << ar2[b] << endl;
}



    return 0;

this shit is mind-raping :dafuckfeels: :dafuckfeels: :dafuckfeels:
Memory is the only hard thing to learn about in C++.
 
9.Vectorized pointer array swap

it became a bit more tolerable and even the code was optimized and became smaller, still pretty much mindfucking.

bear in mind we haven't reached the true mindfucking stage of oop with cons and des and inherits.


 

Attachments

  • vectorized pointer array swapper.txt
    1 KB · Views: 2

Similar threads

svgmn1
Replies
16
Views
538
svgmn1
svgmn1
sennaGTR
Replies
16
Views
1K
Biowaste Removal
Biowaste Removal
E
Replies
88
Views
6K
ldargoblin
ldargoblin

Users who are viewing this thread

shape1
shape2
shape3
shape4
shape5
shape6
Back
Top