Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 627 posts ]  Go to page Previous  1 ... 36, 37, 38, 39, 40, 41, 42 ... 63  Next
Author Message
 Post Posted: June 13th, 2017, 6:19 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2782
Location: Oklahoma, United States
Yumtard wrote:
Notes from part 1:

- pointers are stored in hexadecimal
Spoiler:
Image


lol, just reading this and looking at your avatar makes it better.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post Posted: June 14th, 2017, 1:13 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Yumtard wrote:
Study update

- Watched 4.1 4.2 and 4.3 of beginner at 1.25 speed

- Turned on notifications on youtube for chili. Want that bonus video! :D

- Answered questions from wiki

- Watched part 0 and 1 of intermediate (hype)

albinopapa wrote:
Congratulations and good luck.


ty sir :) have a few decent back up plans if i don't get accepted but I really hope I won't have to use them. Would suck to get this far and not get in.


Glad to see you're digging into the Intermediate stuff. Bonus video probably isn't gonna help you out too much, a lot of the advice I have for people is stuff you're already doing ;)

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 14th, 2017, 2:25 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
@albinopapa

:D I love that pic

@chili

Yeah it's about time :p First vid was very interesting btw. Some of the stuff is kinda hard to wrap my head around tho.

Hype for pointers today!

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 14th, 2017, 8:06 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Study update

- Watched 2.1 and 2.2

- did homework for both

2.1 was some great repetition.
I basically already knew this stuff even though at times, chili had me looking like
Image

Repetition was much needed.

Here's how my hw for 2.1 came out

Code:
int add(int *arr, int size)
{
   int sum = 0;
   for (int i = 0; i < size; ++i)
   {
      sum += arr[i];
   }

   return sum;
}

int main()
{
   const int arrSize = 4;
   int myArray[arrSize] = { 911, 69, 420, 666 };

   cout << add(myArray, arrSize) << endl;


   return 0;
}



So basically the same as in the hw solution video
Image


Moving on to 2.2
Bit more new stuff here, enjoyed it but got a bit confusing when chili went all
https://www.youtube.com/watch?v=8amtq5aXRL8

I was happy to hear pee pees aren't really used much

hw for 2.2
Code:
int add(int *arr, int size)
{
   int sum = 0;
   for (int *e = arr + size; arr < e; arr++)
   {
      sum += *arr;
   }

   return sum;
}


and here's second task. This one actually took me a while to figure out.

Code:
void Reverse(int *arr, int size)
{
   for (int *e = arr + size - 1; arr < e; arr++)
   {
      const int temp = *arr;
      *arr = *e;
      *e = temp;
      e--;
   }
}



And that worked. Pretty close to what chili did but he used a std::swap.
I was also unaware you could increment/decrement multiple variables inside the parenthesis of the for loop.

I will rewatch these 2 videos and write some notes before moving on in hopes of making some of the more confusing parts less confusing

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 10:39 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Study update

Been doing about 5 different super simple console apps (mostly for fun)
Latest one was after watching a youtube video where the question was: What is the average distance between 2 points inside a square with the length of 1?
Code:
#include <random>
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
   double x1, x2, y1, y2;
   std::random_device rd;
   std::mt19937 rng(rd());
   uniform_real_distribution<double>dist(0, 1);
   int sample;
   double total = 0;
   double distance;

   cout << "Samples: ";
   cin >> sample;

   for (int i = 0; i < sample; i++)
   {
      x1 = dist(rng);
      x2 = dist(rng);
      y1 = dist(rng);
      y2 = dist(rng);

      distance = sqrt(((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2)));
      total += distance;
   }
   
   cout << "Average distance = " << total / sample << endl;

   return 0;
}


Edit: Can't post the other ones because I delete them when making a new one so I don't have to make a new project. They're all just as simple and dumb tho

Now I'm gonna rewatch parts of the pointer vids

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 12:01 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Notes

int *p;

^ Declares a pointer that can point to an int

int n = 5;
p = &n

^ use the addressof operator to make the pointer point to the address in memory where n lives.

*p = *p + 64;

^ dereferencing the pointer with * gives it access to the value stored at the address it's pointing to.
For example:
int n = 5;
int *p;
p = &n;

cout << p << endl;
cout << *p << endl;

first line will cout the address of n, where in memory n is stored.
Second line will cout 5, the value stored in that address.

The difference between references and pointers is that a pointer can be retargeted
int m = 3;
int &refN = n; // reference to n
int *p = &n; // pointer to n
p = &m; // retargets p to point to m;
refN = m; // NOT allowed

Pointers also can be declared without being init.
int* p;
like so, while references has to be initilized.
int& ref; //Doesn't work

Always prefer to use variables directly if possible.
If not possible then prefer to use references over pointers if possible (if retargeting isn't needed)

non static member functions has a pointer variable automatically defined for them, called "this"
it points to the object on which the member function was called.

int arr[3] = {1, 2, 3};
int* pArr = arr;

^ pArr points to the first element in the array.
I can also write:
int* pArr = &arr[0];

now if I change
pArr[2] = 69 // it will change the element 2 over to 69

if I make a function that gets an array as argument and need to loop through it.

void loop(const int* arr, int size)
{
for (int i = 0; i < size; i++)
{
cout << arr[i] << endl;
}

// I can also do it like this

for (const int* e = arr + size; arr < e; arr++)
//init *e to point to the address size over where arr is pointing
// as long as arr is smaller than e I will increment arr with one int in memory
{
cout << *arr << endl;
//Keep in mind if I do not dereference here, it will print out the addresses of the ints
}
}

when I increment the pointer, jumps to the next int in memory. An int is 4 bytes so incrementing would add 4 to the address

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 1:13 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3448
Location: Japan
Looks like you got basically 100% of the shit about pointers man. Good stuff.

It's true that you don't need to worry much about int** pp = &p; bullshit. It is used very seldomly, the less it is used the better TBH.

Have you checked out any of the Red Pill videos yet? :)

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 4:28 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Study update

Watched part 3.
A bit tedious when you know there's easier ways to get the same thing done (someone else has already done it for you)
But I still thought it was interesting to find out how this shit actually worked.
The tutorial was great and easy to understand how it worked. Don't think I'd be able to do half the shit on my own without cheating though.

HW

After a lot of thinking and drawing blanks I ended up making a Fib function that I didn't like.
The function seemed ugly and confusing and I knew there should be a better way of doing it. Was trying a few times with recursion but I suck at that and just failed

Here's my dumb fib function:

Code:
int Fib(int n)
{
   int first = 0;
   int second = 1;
   int sum;

   if (n == first || n == second)
   {
      return n;
   }
   else
   {
      for (int i = 2; i <= n; i++)
      {
         sum = first + second;
         first = second;
         second = sum;
      }
      return sum;
   }
}


Also realized I need a function to convert ints to strings. Had some trouble with this too and I aso had to peak for the already made functions (print, read, int2str)
So now it's been a couple of hours and I got annoyed so I'm just gonna check out the solution video :p

Will rewatch the tutorial some time this week.



chili wrote:
Looks like you got basically 100% of the shit about pointers man. Good stuff.

It's true that you don't need to worry much about int** pp = &p; bullshit. It is used very seldomly, the less it is used the better TBH.

Have you checked out any of the Red Pill videos yet? :)


Yay :D
I haven't but I'm planning to :)
My schedule looks like this:
friday: part 4 and possibly red pill pointers
saturday: red pill the stack (and pointers if I got stuck on part 4 on friday)
sunday: Repetition (rewatching parts of the vids from this week)

Then next week I'll finally dive into my c++ book, reading as much as possible and doing as many assignments from it as possible (will post them here, there's no solutions for the assignments in the book)
And take a break from the book whenever a new video is out.

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 15th, 2017, 4:33 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Code:
int fib(int n)
if (n < 2)
{
return n;
}
return fib(n - 1) + fib(n - 2);


Well that was a lot prettier :D

Edit:
Alright I've watched the HW video now. I wouldn't have figured this shit out anyways so I'm fine with the desicion to cheat.
Rewatching part 3 is def on the schedule for sunday

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: June 16th, 2017, 1:36 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
Decided to steal zedthos idea and make a simon says game. I still suck at planning games and always feel back on square one when i start a new project so it will be good practice
Will update on progress later

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 627 posts ]  Go to page Previous  1 ... 36, 37, 38, 39, 40, 41, 42 ... 63  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: