Originally Posted by
thmm
Why would you want to copy a struct ? Pass it as const pointer or const ref.
I don't mean that. But still, it turns out that I'm a complete idiot because I thought that you could not pass "const" variables in "non-const" parameters even when they were passed by copy. I thought I tried it out some at some point and it didn't worked.... Or does it truly not work in specific scenarios? Anyway this is what I thought wasn't possible to do but it is completely possible.
Code:
Code:
#include typedef struct { int val; } test;
void print_and_change_val(test value) {
value.val = 100;
printf("The modified value is: %d\n", value.val);
}
int main() {
const test t = { 200 };
printf("The value inside 'main' is: %d\n", t.val);
print_and_change_val(t);
}
Aaaaaaaaaaaaahhhhh!!!! Why am I so stupid and lazy????? Mostly the last one....