You define db in main but do not set its value (initialization or
assignment). Since db is passed to openDb by value, the compiler
correctly notifies you that this is invalid. This indeterminate value
is then copied to the local variable db in openDb. You pass the
address of this local variable to sqlite3_open which will replace the
current value by dereferencing this address. The local variable db
now contains the result of sqlite3_open. Unfortunately, this local
variable is destroyed when openDb returns. The end result is the
variable db in main still has the original indeterminate value (which
happened to be NULL on your system).
You apparently wanted openDb to change the value of db in main. The
way to do this is:
Call openDb with &db as the second argument. (Since you are not
passing the value of db, the fact that its value has not been set is
irrelevant. The address of db is a valid address regardless of the
value it points to.)
Change the signature of openDb to receive sqlite** instead of
sqlite*. (Since db in main has type sqlite*, &db has type sqlite**.)
Change the call to sqlite3_open from &db to db. (db in openDb has
the correct type, sqlite**. Its value is the address of db in main.
sqlite3_open will dereference the value it receives and update the
variable pointed to, which happens to be db in main. At this point,
db in main will contain the value (address) you need it to.)
It would be easier to understand these concepts if you used different
names for the variable in main and the parameter in openDb. Using db
for both variables led to wrong conclusion that when sqlite3_open
updated db in openDb it would somehow affect the value of db in main.
--
Remove del for email