Pag 41 tokens


#1

When swapping the tokens, I tried three things:

#1 replacing the %s with %d:

[code]#include <stdio.h>
#include <stdlib.h>

void congratulateStudent(char *student, char *course, int numDays)

{
printf("%d has done as much %d Programming as I could fit into %d days.\n", student, course, numDays);
}
int main (int argc, const char * argv[])

{
congratulateStudent(“Mark”, “Cocoa”, 5);
sleep(2);
congratulateStudent(“Bo”, “Objective-C”, 2);
sleep(2);
congratulateStudent(“Mike” , “Python”, 5);
sleep(2);
congratulateStudent(“Ted”,“iOS”, 5);

return 0;

}
[/code]

[quote]3841 has done as much 3846 Programming as I could fit into 5 days.
3852 has done as much 3855 Programming as I could fit into 2 days.
3867 has done as much 3872 Programming as I could fit into 5 days.
3879 has done as much 3883 Programming as I could fit into 5 days.
Program ended with exit code: 0[/quote]

#2 replacing the %d with %s:
The debugger gives a nice illustration of the error.

#3 replacing both %d with %s and %s with %d
The debugger gives a nice illustration of the error.

For the situation #1.
What are those 4 digit numbers printed ?


#2

When you pass a char *, you are passing an address in memory where a several characters are stored. The number, then, is that address. (Or actually, it probably gets truncated down to a 32-bit number and that is what you see there.)