Nan Ma
Nan Ma

Reputation: 1085

What is wrong with this excerpt?

I'm reading the book The Practice of Programming by Brian W.Kernighan, and I don't quite understand exercise 1-5 in it.

Exercise 1-5. What is wrong with this excerpt?

int read(int *ip) {
    scanf("%d", ip);
    return *ip;
}
    ...
insert(&graph[vert], read(&val), read(&ch));

Upvotes: 5

Views: 271

Answers (1)

Yu Hao
Yu Hao

Reputation: 122443

insert(&graph[vert], read(&val), read(&ch));

It's unspecified whether read(&val) is called first, or read(&ch) is called first, so you never know which one you are inputting.

Upvotes: 16

Related Questions