int i = 10;
Q. Is this code correct?A. Yes.
2.
extern void bar(void);
void foo(int *x)
{
if(x == NULL)
{
return;
}
int y = *x;
bar();
return;
}
Q. It turns out if you check the validity of your variables before you use them it prevents you from having to understand undefined behavior.A. Is there a question here?
3. There was a function:
#define ZP_COUNT 10
void func_original(int *xp, int *yp, int *zp)
{
int i;
for(i = 0; i
I optimized it this way:...because nobody had any idea what it was doing and so it wasn't used anywhere.
4.
double f(double x)
{
assert(x != 0.);
return 1. / x;
}
Q. Is it possible for this function to return inf?A. If you're at the point where you're asking that question you should have been using a decimal library a long time ago.
int my_strlen(const char *x)
{
int res = 0;
while(*x)
{
res++;
x++;
}
return res;
}
Q: The provided above function should return the length of the null-terminated line. Find a bug.A. They didn't use `strlen()`.