We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Multiple Types

So we saw that we can push both int and int * types into the same stack (again, a bad idea).

In this example, we'll see that not only can you push values and pointers into the same stack, but you can also push different types of values into the same stack.

This is once again a terrible idea, but the thrust of what we're getting at here is:

C doesn't care what you put in memory, it's bytes all the way down.

Fortunately, C doesn't let you do these conversions automatically... but it still lets you do them. When you're working with void *, you're working with raw memory addresses, and you can cast them to whatever you want.

Assignment

Complete the stack_push_multiple_types function.

  1. Remember to leave room for the null terminator (\0)!

Tip

Don't forget to use the string.h library when working with char * types.