When I run the program below, it prints \"one: 1\", instead of \"one : 1, two: 2\", as I had expected. Anyone know what\'s going on here? I am trying to create a function th
To understand the problem in detail, please go through The C Programming Language
by Kernighan & Ritchie
- Introduction (chapter 1.7/1.8) and Functions and Program Structure (chapter 4).
Hint: pass-by-value
& pass-by-address
int main() {
...
add(2, "two", &head1);
...
}
OTOH, you should validate the return address of malloc
before de-referencing it (in createNewLinkedList
).