I was asked this on a practice test, that has no answers posted. I have no way to test the code, but it has confused me. Can you please help me out with not only understanding the answer, but why.
int foo() {
int a = 1;
char b[] = "zapples";
a = *(b + 1);
if (a == 'a') return 1;
else return 0;
}
What does foo return? ____
Have they taught you how C pointers work?
I’m not going to give you a straight answer, but think about this:
bhas the starting address of string “zapples”. This means thatb[0]points to “z”. Another notation for this is*(b + 0), that is, “the value contained at addressb, with an offset of0). With this information, what is the value of*(b + 1)?This should be enough to solve the exercise.