A.
fflush()
is for output files only. Its
behavior is undefined for input files. Since the newline
(\n
) is a character like any other character, add a command
to read this extra character (you don't have to do anything with it,
just ignore it).
A.
Well, for example...
int *ip;
says that "ip" is a pointer (the star) to an int
.
I.e., the star says that it is a pointer to the type to its left
(int
). So,
int **ipp;
would be a pointer (right-most star) to a pointer (left star) to an
int
.
free()
some memory I can still access it?
A.
When you free()
memory, you are essentially just promising
not to use that memory anymore (i.e., it allows a call to
malloc()
to give that memory away again)... If you try to
access some memory that has been freed, you often can (although it may
depend on exactly how dynamic allocation is implemented on a system),
since the memory doesn't go anywhere, it's just that you're not
technically allowed to use it anymore.
So, you should not try to access memory you've freed.
typedef A *B;
A.
That typedef
defines "B" to be a new type, which is the
type of a pointer to A. I.e., the following 2 would now be
equivalent:
A *ap; B ap;
int f1(void); . . . void foo(void) { f1(); }
A.
That works just fine. We do it all the time...For example,
printf()
returns an int
, but that return
value is rarely used.
return (a == b);
equivalent to:
if (a == b) return 1; else return 0;
? I.e., 1 is returned if the == statement is true, 0 otherwise?
A.
Yes.
switch
always get executed,
or just when none of the cases apply?
A.
It is executed when none of the cases preceding it apply. Or when the
case right before it lacks a "break".
int whatever(...) { if (...) { ... return x; } if (...) { ... return y; } /* No return here. */ }
A.
The problem is that there is some point in your function that could be
gotten to that does not return a value. Since the function says it
returns a value (i.e, the function's return type is not void
),
it must always (i.e., under every circumstance) do so.
Can we give parameters names (such asvoid StackPush(stackT *, stackElementT);
stackT *stackP
)? If
not, how are we supposed to refer to it in code?
A.
Prototypes don't need parameter names, though you should put them if it
adds to readability (not necessary here since the types stackT
and stackElementT
are quite explicit). The function
definition, however, will need parameter names, and you should
choose something reasonable for those.
if (isdigit(c) == 1) ...
A.
You've assumed that the boolean function returns 1 for a true value.
Remember that many testing functions just return some true
value on truth, not necessarily 1.
You should use idioms like:
rather than comparing to 1 or 0.if (isdigit(c)) ... if (!isdigit(c)) ...