Write a program that contains both a main function and a


1. Write a program that contains both a main function and a function called swap. Your main program should read in two integer values from the keyboard and then call the function swap. The swap function will swap the original values and then return back to main. The function main will then output the values contained in the original variables. The original values should be swapped. No global variables are to be used. You must simulate call by reference by passing the address of the variables to the function swap. You must be able to do this. Do not use an array. I want you to practice using the address operator (&) and the dereference operator (*). You need to learn how to deal with pointers as a simulation of call by reference in C.

2. Write a C program that will malloc up space dynamically. The space should be able to hold exactly one integer value. After the space has been reserved, you should deposit the number 6 into the space. After the number 6 has been deposited into the space you should print the value that the space currently holds (that is, 6). You need to create a variable that contains a pointer to an int. Do not use an array index operator. Once you are done, you should free the allocated space explicitly.

3. Write a program that will first read in a positive integer number, say n, from standard input. Then you need to create enough space in the heap via a call to malloc to hold an array of n integers. You then need to use array index operators to fill the array with n integer values entered by the user via calls to scanf. The index operator is also referred to as a subscript operator (i.e., A[i]). After the array has been filled with numbers, your program should walk down the array and build their sum. Print out the sum.

Solution Preview :

Prepared by a verified Expert
Business Management: Write a program that contains both a main function and a
Reference No:- TGS02237062

Now Priced at $15 (50% Discount)

Recommended (90%)

Rated (4.3/5)