Chapter:C const

From Juneday education
Jump to: navigation, search

Exercises const

1.

Compile the file const-int-01.c to make sure it works.

Change the value of the variable i on a line after the initialisation and recompile. Does it work? Why?

2.

Declare a pointer to int variable. Call the variable harold (after the famous author), Assign the variable harold the address of i.

Assign 129 to the memory address harold points to - you need to dereference harold to do this. Does the compile and produce a binary?

4.

We shall now change the assignment to harold a bit. Typecast the address of i like this:

(int*)(void*)&i;

Does it work? Why?