Holy shit Jow Forums today i just figured out pointers.. i felt like a complete brainlet before...

holy shit Jow Forums today i just figured out pointers.. i felt like a complete brainlet before. am i ready to get a job now? rest of my class still doesnt understand how these work kek

Attached: Screen Shot 2018-06-16 at 00.50.42.png (344x188, 17K)

congrats

Aw, yr cute.

Attached: computer science.jpg (2592x1936, 610K)

Learn monads

You have to be 18 to post on this site

you really don't have to use pointers often in c++ unless you're doing something complicated, libraries handle it for you most of the time

No, understanding how pointers work and how addresses in memory can itself be used as a variable is the basics of what you need to know to be a decent programmer. Keep learning things

its just a variable that points to another variable

is that the B&N in downtown boston/copley

I once read that the 3 big concepts that act as the gates to people "leveling up" in programming ability are assignment, recusion and concurrency.

Sort of. Keep studying.

Yes

points to the variables location in memory*

>mum look at me i know what pointers are!
>i can get a job now?!

no you can't faggot

kys

>am i ready to get a job now?

It really depends user. Before hiring you, I would ask what you think the output of that program of yours would be.

I always thought of them as how windows treats "shortcuts"

>int main() {
>using namespace std
kys

would log the the memory address of x

>implying i dont know how namespaces work
look at the program faggot. what is the issue of using namespace here.

>It's ok mom! I only did a liiiiiiittle bit of heroin!

>t. 16 and trying to fit in

>int* ptr
you don't

You are a retarded nigger

>he would actually write "int *ptr"
Everyone look at him! Look at him and laugh!

it's a variable holding an address, C's workaround for not supporting call-by.reference

Nope.
Every modern language has already deprecated them.

What is the advantages of using pointers?

What are*

holy shit I'm struggling

pointers are fantastic way to get yourself in trouble in a hurry

Devils trips got you.

In theory here's a couple things, but basically the idea is that you can do things with variable scope and pass addresses instead of values into functions.

In practice, they're a pain in the ass.

congrats user, what are you learning next? how to do strings in C?

>Strings in C

Attached: 1528564629372.jpg (281x292, 19K)

Example: Pointers make it convenient to return an error code and have a side effect on some operation. Imagine a stack data structure:

int pop(int *out)
{
if (top == 16)
return 0;
*out = stack[--top];
return 1;
}

holy shit Jow Forums today i just figured out arithmetics.. i felt like a complete brainlet before. am i ready to get a job now? rest of my class still doesnt understand how these work kek

Attached: ABCArithmetics.gif (403x306, 17K)

whoops, should have been if top == 0

>int *out instead of int* out
Fucking die, you disgusting cunt!

It is the correct way to do it.
The following looks weird with the int* syntax:
int *a, b, *c, *d, e, *f;

>everyone making fun of the dude for understanding pointers
>mfw Im employed with a decent salary and still cant use them
I survive with my python and bash scripts plus knowledge on maintenance

???

holy shit Jow Forums today i just figured out grep. i felt like a complete brainlet before. am i ready to get a job now? rest of my class still doesnt understand how these work kek

Attached: images.png (199x254, 4K)

Declaring more than one variable is stupid.
int a, b, c, d, *oh_look_im_special, e, f, g;
Fuck you.

Good on you bro! Keep at it!
Take your time with the basics:
> low level
> OS
> Alg analysis
> math
You'll get there eventually dude

the concept is really just about fucking storing memory addresses. deep, shallow copies etc.

if you're programming at all you should know what hell it is.

Strings don't exist in C. You're thinking of char arrays
I suppose you can make a string struct by having one pointer to the start and one pointer to the end, but then you'd need to implement the rest of the standard library

You can work with memory directory and dynamically.

Think of linked-lists. You can create a ton just using nodes and linked-lists. All extremely efficiently too.

Attached: linked-list-ex.jpg (393x132, 11K)

Strings are really always just char arrays, abstracted or not.

Guy is joking anyways i'm sure.

So it's like "hey bro wanna see something cool? Then just head to [address] and ill return it"

Strings are implemented as char arrays but char arrays are not strings. Strings don't fuck up when you forget a null termination

more like "hey bro i want to refer to this memory address because I know it is exactly the reference to what i want" (the reference is basically a physical part of the RAM stick too, abstracted on tables though)

>Strings don't fuck up when you forget a null termination

Because that part is abstracted away too user.

In C a string is defined as being a null-terminated char array
its as simple as
char str[] = { 'u',' ','w','0','t','\0',' ','p'};

Technically the string stops at the \0, and the space and p are not included, but the memory space is still available for use.

Ye i feel this. I think i mostly get pointers

Wow, now you two are so close, you can meet up, and.. you know, suck eachothers dicks and shit.
Remember to add datestamps. No homo tho.

t. nigger

pointers are dirty hacks

why? seems useful for passing into a function so that you can edit the value globally.

How to UTF8

I seriously can't understand how pointers can be so fucking hard to understand for some people.

This is what helped me really get pointers:

#include

int main()
{
int color = 0xc0ffee;

unsigned char red = *(char *)&color;
unsigned char green = *( (char *)&color + 1);
unsigned char blue = *( (char *)&color + 2);

printf("%d %d %d", red, green, blue);

return 0;
}

>The following looks weird with the int* syntax:
That's because the design itself is stupid. Pointers should be part of the type.

You are ready to take your first programming class in high school/college

thanks for this. i think i get it now.

red gets the address of color then points to it with a char type pointer and the dereferences it to give the color's int in its char form.

green does the same but adds 1 to the address and same with blue but adds 2.

Strings should have a primitive type

>assuming
i do int * ptr faggo

brainlet

yeah, basically it says "you see this memory(color, 32 bit)? read it as if it was a char (8bit)"

and then you just offset the starting posiiton. memory is just a linear set of bits anyway

anything other than
type *variablename
is degenerate and misleading pajeetery

dumbo

its how it works on the lower level, C is just portable assembly

Come back when you figured out advanced Haskell programming faggot

Now let function pointers blow your mind.

I really dont understand why you have to have teachers to explain you something as trivial as pointers. No wonder IT is in shit.

they cant be a primitive type simply by virtue of not being a small byte size that can hold a large range of values.

You can encode 8 letters in a 64 bit register.

Should I learn pointer if I mainly do java?

Attached: 1518405958902.jpg (284x284, 15K)

Learn to make fucking linked lists. Pointers are just about understanding RAM.

Yes, you should. Not knowing what a pointer is in programming is like not knowing how to cook eggs as a chef.

Don't exaggerate. Pointers are mostly useful for critical performance systems.

Make a linked list without pointers.

Don't worry, you are still a brainlet

Is this a challenge. Can you actually do this

I can't think of any way to do that in C. C++ has std::optional at least.

Try doing callbacks without pointers.
>protip: you can't
>inb4 &
That is not C

so a pointer is near literally a variable.. ? but without having to define it
so like a dumb variable found in javascript / php etc

>What is the advantages of using pointers?
It's needless overcomplication introduced by insecure nerds so they can feel more smug about their elitist coding style

There are no advantages - you simply REQUIRE pointers for lots of operations. Languages and libraries often hide that, but it's all pointers underneath.

that's great user let me introduce you to char**.

You need objects to live beyond the scope of the individual nodes so I don't think you can do it without pointers.

hehe. pointer to a pointer. did you really think i didnt learn that user.
>pointception
char *ptr1 = new char;
char **ptr2 = &ptr1;
char ***ptr3 = &ptr2;

lmfao
>celebrating fundamental c/c++ language concepts
>no longer a brainlet
kys

you won't need as many variables

if you need to call a function to change the contents of a struct, you could return a struct or you could simply use a pointer and heap memory, avoiding the need of two structs.

wait until you discover the magic of the void pointer.

>( char * )

Attached: pp,550x550.u1.jpg (550x422, 35K)

it goes like this
-- pointers
--- void
---- casting to void
----- HolyC
------ Girl with a white rabbit tattoo knocks on your door

>cout

But user, that's impossible. No one knows what they are.

Attached: 1529032860347.gif (220x258, 168K)

Senpai how do I into entry level job? I don’t need much, only enough money to pay rent and feed the children

Let's say you have a 100GB file you want to do some operations on.
After you read the file, it's stored in memory as some variable.

You need to pass that file to a function that does some operation on it.
If you did it with a pointer, you pass the address where the file is stored in memory. There remains only 1 copy of the file in memory.
Otherwise, you would create a copy of the file to pass to the function. Now you have 2 copies of the file in memory.

>confused by monads
>better learn some category theory
>spend two years doing nothing but math
>tfw when a monad is just a monoid in a category of endofunctors
>clarity achieved

Pointers get a shitload easier to understand when you look at how stuff is stored in memory, and when thinking about the stack.

The only reason pointers are confusing in the beginning is that the same symbols have different meanings, C++ makes this worse than C because of references.
If C used something like @ for dereferencing a pointer instead of *, then it would have helped. My guess for the reason they didn't do that is because when C was created not all keyboards had a lot of symbols, that's why they limited the symbols used. That's why you also had trigraphs where you could type??'and it would be same as typing^