First off thank you for the in depth response. I running on Debian Linux with mostly editing c/c++ in clion by idea. As for my experience, no college but many years of professionally messing around with "programming" but not in the typical sense. I did a lot of g-code which is used on cnc machines and pcdmis which is used on CMMs. I also did some "programming" in excel and power bi and sql. I had some exposure to c# and was "trained" in python but that training was pathetic(3 month course and about 1/2 the class admitted during final presentation that they wrote their entire final project as 1 function because they couldn't figure out to to pass variables in to functions or get resulting variables out... Every student still passed).
Most of this was just for confirming what I hear and learning more about how it works. For example I've see many places claim that primitives are always on the stack, I never considered an int * =malloc(sizeof(int));. But that makes sense that it would be heap allocated and I can see some uses.
I realize a lot of this doesn't really matter, especially with modern computers but you are I think the third person to say "that's not technically always" or something with similar meaning. Yes I'm sure I can read books and papers and learn the edge cases but I'm still trusting that author. I was curious if I could prove it, or disapprove it on any system.
My only way of verifying this that I can find is verifying copy. Basically make a variable and set it to something, make second variable and set it equal to first, modify second variable, test if variable 1 == variable 2. If yes, it's heap allocated, if not it's stack allocated. My understanding is no matter what you create, a value is created on the stack. The difference is if stack allocated the data is stored directly, if heap the data on the stack is a pointer to an address on the heap. As such if you copy the variable, your copying the value in the stack. If it's stack allocated the data is literally copied and you have the same data in two places, when you modify one the other is left alone. If it's heap allocated, the address is copied into a new spot on the stack, but since both point to same address if you modify one you modify both.
Yeah, none of this will likely matter in any job or any project I do but if I was told something I want to KNOW it's true. Plus if I'm doing something special, it would be nice to have confirmation. Like if I'm on a arduino or es32 do they use the same memory configuration? What about a fanuc cnc controller? A cognex aoi camera using "spreadsheet" mode(that is probably no since it's literally programmed via a spreadsheet) ? Yes you MAY be able to tell me but even then I have to trust that you know it, it wouldn't be the first time Ive seen manufacturer employees quote incorrect information to me.