is this a fair quiz question? its from my engineering class and I feel my professor gives us overly difficult questions, like for this question I think its designed to trick you because &y becomes *x in the function when there already is a variable x in the main. it seems like its bad practice to reuse variables like that
so is this actually a bad question or am I just a brainlet? looking back yeah I should have gotten it right but when you only have like a minute per question on a quiz its easy to make small mistakes
Alexander Torres
You're a brainlet.
Major in something in liberal arts.
Christopher Gray
im good at maths tho I literally dont know why C is so hard for me to understand like im doing better in my calc 3 and my electricity and magnetism class than my intro to C class wtf
Aiden Hall
Programming requires a different mindset and pointers are brainlet blockades.
Jordan Reed
I think I got pointers down now though basically a pointers is a variable with type pointer and it must be an address?
and then you just send an address to a function and then have its formal parameter be a pointer and then you can modify it without returning anything?
wtf fuck C there should be an actual call by reference function
Oliver Ramirez
If you can't solve this within a minute, or actually half a minute, you need to go back to the basics and do some rereading.
Literally the only relevant part of silly() is the last line.
IT'S *x = 2 * *x
2 * x
Carson Peterson
C is a horrible language with no type, thread or any other sort of safety. Just accept it learn it and move on. It's useful for learning some things but you really shouldn't write production code in it unless you have no other option.
Jason Scott
this would be better if it was y = *x++ + 2;
instead
Wyatt Stewart
yes but thats not the confusing part, what I didnt like is the argument y becomes *x when there already is an x in the main
Carson James
What the fuck is this formatting? Why is void on a separate line? Am I the brainlet for not understanding it?
I've only had professors use obscure variable names in one course, and we were learning about inheritance and frames so it was kind of the point. This really isn't very obscure though, it should be pretty obvious desu
Brayden Peterson
20, 22
Jonathan Lee
This interests me. I liked calc and physics but I wasn't naturally very good at them at all. I had to study so hard to pass. With C, I feel like I never miss a beat It's also way more enjoyable because you're not just plugging and chugging like with most math. Instead you have figure out how to make something that you can plug and chug things out of which is pretty neat in my opinion desu It feels almost like a creativity-based subject to me >It's probably important to note I'm pretty much a brainlet and had a hard time even learning Java until I learned C, which made everything after easier. It's different for everyone so don't give up
Thomas Adams
It's an exercise to make you better at reading C code and not getting confused with shit like this later. You can hate your teacher now, but later in your life, when you will be debugging a huge pajeet mess, you will thank him.
Justin Robinson
I never understood pointers. Pretty sure I BSd my way through my C and C++ courses. But for some reason I really liked Java and it clicked a lot more with me, might have been because I was more mature or because the professor was a lot better I don't know, but I just use java at my job now so it's p. Neat.
Cameron Ramirez
Also, I'm getting sleepy and haven't taken a good look yet, but I'd check out how "int main(void)" is affecting things, it causes different outcomes than in C++ vs. when you just use int main() >captcha: farts dempere
Caleb Moore
Let's say I define a mathematical function f(x) -> x * 2. Now, no matter what I put into said function, internally the variable becomes x. If I say let y = 3, then do f(y), then the x within f(x) becomes y.
Ayden Allen
>Why is void on a separate line? Because it can be, and because it allows for the function name to be the first thing in the line, rather than the output type.
Eli Campbell
Lemme make this easy for you on one picture. On the picture, how the computer memory work pretty much, with each of the lockers having a number, and fitting a byte inside. Variables are just cute names given to those numbers. Like, when you: int miltank_gives_me_nightmares=0; All C will do is get one (or in this case four) of those "lockers", reserve it and name its number as miltank_gives_me_nightmares.
A pointer is simply passing the real number of the locker instead of what's inside the locker.
Elijah Hall
How is that a trick? Variables get passed to functions.
Grayson Jones
Why do people always say this to explain pointers?
I know all that already
It doesn't mean anything to me
John Harris
What confuses you then?
Grayson King
I appreciate this explanation user For some reason I read it in a Russian accent
Levi Sanders
>wtf fuck C there should be an actual call by reference function t. Faggot. Pointers are great and being explicit about value and reference semantics is great for reasoning about side effects.
Jaxson Cook
Passing &x is actually fairly common in C libraries, especially if you need to return multiple values. It's especially commonplace in some low level libraries like intel IPP where you get functions like IppStatus ippsIIR32f_16s_Sfs(const Ipp16s* pSrc, Ipp16s* pDst, int len, IppsIIRState32f_16s* pState, int scaleFactor);
Logan Rivera
If only C had multiple return or tuple return like a modern language.
Jaxson Nelson
C is too low level for this kind of crap. Your modern ((arrays)) do a bunch of shit under the hood.
Caleb Price
>C is too low level for this kind of crap. Do you even know what a tuple is? It's arguably even more low level than a struct. You're brain damaged and can only think in terms of C.
Aaron Bailey
If you just plug and chug in your "math" classes then that mus have been a shit school
Hudson Wood
The whole variable lengthness of a tuple means you have to have a tuple length thing hidden somewhere, and manage it with extra code etc..
Mason Morgan
>it seems like its bad practice to reuse variables like that The point is to see if you actually understand what you're learning, not examples of usable code. He even named it silly and commented that it's nonsense. Is engineering usually full of autists like you?
Colton Watson
Tuples aren't variable length though. The length of a given tuple type is fixed at compile time.Those are arrays, or perhaps dynamic arrays/vectors.
Tuples are literally just structs but with positional instead of named data items. In a language with destructuring syntax, multiple return via tuples ends up more readable and more efficient (RVO/copy elision + no aliasing) than out parameter hacks.
Parker Lee
I think i ran out of arguments against it. Was thinking on some messy thing that you can add more parameters at runtime, but don't seem to be the case for tuples. Would be a bit messy to put tuples in the fixed variable types of C, but other than that it probably just works.
Hudson Gonzalez
What is that shit tier formatting?
Ryan Collins
Not really. Take a simple struct like this. struct Result { int value; struct Flags flags; }; In a language with tuples like Rust, this return type could just be expressed inline in the function signature with a tuple. fn some_function(i32) -> (i32, Flags); And then destructuring syntax makes it effortless to take the pieces apart. let (value, flags) = some_function(32); Even C++ has analogous syntax nowadays, although it's a lot uglier since that's C++. std::tuple some_function(int); auto [value, flags] = some_function(32); In the end, it compiles down the same way it would if you were to return the Result struct in C and manually pick apart the data items.
Samuel Phillips
See? C++ does it! Quite horribly, in a way that probably is not worth using, but it does!
Brandon Morales
I'd rather use return a std::tuple than use out parameters desu. But having tuples and variants as part of the type system and not an adhoc library feature is a lot better than. Only ignorant code monkeys need to be told that C++ is a halfassed piece of shit.