by outsomnia · 5y ago · 0 comments
I stopped even scanning it when the "solution" for the "common beginner mistake" of array overflow is not sizeof() but
``` { const int len = 5; int a[len] = {1,3,5,7,9}; ```
> if you want to modify a value you either have to use a pointer to the memory address:
void increment_a(int *a)
{
*a++;
}
int solve(void)
{
int a = 5;
increment_a(&a);
} *a++
doesn’t increment the value pointed to by `a`, it increments `a` itself. The value remains intact. int increment(a)
{
return a+1;
}
void somefunc()
{
int b = 5;
b = increment(b);
printf("b now %d\n", b);
}Noob mistake
if (f != 1.1)
puts("Do not compare a float to an integer value\n");
if (d == 1.1)
puts("But that's okay for a double\n");
In the back of my mind there's the fear that all of this was actually mean seriously... prog.c: In function ‘somefunction3’:
prog.c:8:2: error: variable-sized object may not be initialized
int a[len] = {1,3,5,7,9};
^~~