"I added const to the dict argument in get () so that the compiler warns me if I try to change the dict address by pointing to"
In this case, you meant Dict *const dict , not const Dict *dict . You declared a struct as const, not a pointer to it.
"Why do I also need to have const for currPtr"
Because otherwise you could use currPtr to change the very structure of the dictionary, which should be const in this function.
"The string currPtr = currPtr-> next; changes the currPtr pointer, so why the compiler did not warn me about this if I added a constant to currPtr"
For the same reason: it is not a mistake if the constant is in the place where you put it. It would be if the constant was elsewhere for currPtr.
otherwise, I will not be able to access the dictionary in the main program, because I lost the address that I also pointed to
No - when the main program calls are received, it passes the value of the pointer to the procedure, and this becomes the dict value in the get function. But get has its own pointer variable, separate from the one in the main program. Even if they just happen to both, called "dict", changing one pointer will not change the other.
Both variables point to the same structure, therefore, if you use a variable to change any of the fields in the structure, then, of course, the results will affect both bits of the code. Usually, a function called "get" will work read-only, so you can make the const Dict * parameter. But I think the reason that this is correct is a little different from what you think. This is to protect the contents of the dictionary from being changed, and not to protect your record of its address.
However, const-safety is a little inconvenient for linked lists like this. Even if you have a const dict, its “next” field still does not point to const. Therefore, although you cannot change the first node, the const system will not protect you from changing other nodes in the list. C ++ addresses this with function overloading, so you can have a getnext function that returns const output if the input is const, but non-constant output if the input is not const. You can achieve a similar thing in C with "getnext" and "getnext_c", the latter having a const parameter and returns. But most people don't care, including standard library functions like strchr, which in C accept const char * but return not const const char *. Therefore strchr can be accidentally used in C to convert a const string to a non-constant string, without any warnings. Or intentionally, in which case it is a bit like money laundering through a “legitimate” business; -)
does the del () function not require me to add a constant before currPtr and prevPtr?
I confess I'm at a standstill. I would expect the same warning as in "get" - are you sure that it is not there? But the to del parameter should not be const any, because you are potentially changing the fields.