Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write C statements for the following. Assume that x is declared as int Declare a

ID: 3682502 • Letter: W

Question

Write C statements for the following. Assume that x is declared as int Declare a pointer to an int, call it p Set p to point to x Set the value of x to 7 using p Print the value of x using p Print the memory address of x using x Print the memory address of x using p Consider the following program with only the variable declarations shown. For each statement, specify if it is true or false. Function alpha can access the external variable x In the inner block of the main function, the block variable y hides the local main variable y The declaration of variable k at the given location generates a compilation error Function beta is the only function that can access global variable x Write a recursive function countDown that prints numbers 1 to n in descending order Consider the following function. Complete the function so it sets the sum of a, b, c in the variable pointed to by sum and their minimum in the variable pointed to by min

Explanation / Answer

int x;

1. a. Declare a pointer to an int, call it p

int *p;

1 b. Set p to point to x

p = &x;

1 c. Set the value of x to 7, using p

*p = 7;

1 d. Print the value of x, using p

printf("%i ", *p);

1 e. Print the memory address of x, using x

printf("%u ", &x);

1 f. Print the memory address of x, using p

printf("%u ", p);

2. a. Function alpha can access the external variable x. True.

2 b. In the inner block of the main function, the block variable y, hides the local main variable y. True.

2 c. The declaration of variable k at the given location generates a compilation error. False.

2 d. Function beta is the only function that can access global variable x. False.

3. Write a recursive function countDown that prints numbers 1 to n in decreasing order.

void countDown(int n)

{

if(n != 0)

{

printf("%i ", n);

countDown(n-1);

}

}

4.

int findSpecial(int a, int b, int c, int *min, int *sum)

{

int sumAll = a + b + c;

int minAll;

if(a <= b && a <= c)

minAll = a;

else if(b <= c && b <= a)

minAll = b;

else

minAll = c;

*sum = sumAll;

*min = minAll;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote