answer the questions The following program has comments inse
/*answer the questions
The following program has comments inserted into it asking you to do
certain things. Put your answers next to them
*/
#include <stdio.h>
// Q1: What is the purpose of the following line? Don\'t just say what it does. Make sure to describe what it is used for.
#define SIZE 5
// Q2: What are the next two lines called?
void modifyArray(int b[], int size);
void modifyElement(int e);
int main(void)
{
// The next questions apply to the declaration of the variable a:
// Q3: What kind of variable is a? Be complete, including mention of the data type.
// Q4: What does SIZE do in the declaration?
// Q5: Describe what the numbers between the curly braces do.
int a[SIZE] = {0, 1, 2, 3, 4};
int i = 0;
printf(\"The values of the original array are: \");
while( i < SIZE )
{
printf(\"%d \", a[i++]);
}
printf(\"\ \");
// Q6: The use of the SIZE parameter helps modifyArray immensely. How is modifyArray improved by SIZE being passed as a parameter?
modifyArray(a, SIZE);
// Q7: What would happen to the program if we left out the i = 0 line?
i = 0;
printf(\"New values are: \");
while( i < SIZE)
{
printf(\"%d \", a[i++]);
}
printf(\"\ \");
// Q8: What would happen if we left out the [3] in the line below? Why?
printf(\"The value of element 3 is %d\ \", a[3]);
// Q9: What data type is a[3]?
modifyElement(a[3]);
printf(\"The new value of element 3 is %d\ \", a[3]);
return 0;
}
void modifyArray(int b[], int size)
{
int j = 0;
while( j < size )
{
b[j] = b[j] * 2;
j++;
}
}
void modifyElement(int e)
{
e = e * 2;
printf(\"Doubled to %d\ \", e);
}
// Q10: Write a function called reallyModifyElement that takes a pointer
// to an int as a parameter and multiplies by two the contents that
// are pointed to by the pointer. Comment it with a function comment
// and inline comments as appropriate. Use 4 spaces instead of TABs
// for indentation.
Solution
1. Preprocessor macros get literally swapped in during the preprocess stage of the compilation.
will get swapped for
when the compiler sees it. It does not have a size of its own as such.
2.
3,4 and 5. The variable a is declared as an integer array with a size of 5 and it is initialized to
a[0] = 0, a[1] = 1, a[2] = 2, a[3] = 3, a[4] = 4 .
6.

