Pointers and Arrays

Exercise 1

Try to create a function Swap(). This function must exchange the value of two variables.

For example: if i=123 and j=456, then i=456 and j=123 after the Swap() function has

been called. The variables i and j are declared, initialised and printed in the

function main(). This problem can be solved by using pointers as arguments for

the Swap()function.

Exercise 2

The following program reads a string with a 30 character maximum. Implement

the Length() function. The function Length() must determine the length of the string.

Give Length() the address of the array as argument.

Note: your Length() function should be similar to the built-in strlen() function so your

job is to mimic that function without using it.

EOF is used in the function main(). This means End-of-File and is discussed later on in

this document.

In DOS, EOF can be entered by the key combination Ctrl-z (often written as ^Z). With

^Z (Say: control Z) is meant pressing the control-key and the z-key simultaneously.

Leave a Reply

Your email address will not be published. Required fields are marked *