Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this excerpt?

Tags:

c

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));
like image 851
Nan Ma Avatar asked Aug 06 '14 07:08

Nan Ma


1 Answers

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.

like image 168
Yu Hao Avatar answered Sep 22 '22 18:09

Yu Hao