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

Ansswer the following questions in C program: a) Suppose you have these declarat

ID: 3818472 • Letter: A

Question

Ansswer the following questions in C program:

a) Suppose you have these declarations:

float rootbeer [10], *p, value = 2.2;

Identify each of the following statements as valid or invalid and explain why if it is not valid.

1) rootbeer [2] = value;

2) scanf("%f", &rootbeer );

3) rootbeer = value;

4) printf("%f", rootbeer);

5) p=value;

6) p=rootbeer;

b) What will this program print without running the code?

#include <stdio.h>

int main (void)

{

int ref [ ] = {8, 4, 0, 2};

int *p;

int index;

for (index = 0, p = ref; index < 4; index++, p++)

printf ("%d %d ", ref [index], *p);

rerturn 0;

}

c) In question (b), ref is the address of what? What about ref +1? What does ++ref point to?

d) Waht will the following program print without running the code?

1)

int num [ ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9}, *pnum = &num [2];

pnum++;

++pnum;

printf ("%d ", *pnum);

2)

int num [9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}, *p;

p = num;

*( p + 1) = 0;

printf ("%d,%d,%d ", *p, p[1], (*p)++);

Explanation / Answer

1) rootbeer [2] = value;

Valid as its accessing memory which rootbear asked for.

2) scanf("%f", &rootbeer );

Valid storing at rootbear[0], rootbear represent first adress.

3) rootbeer = value;

Invalid, its trying to assign incompotible type (float to float[10])

4) printf("%f", rootbeer);

valid compiler wise (errornous logic wise)

5) p=value;

Invalid, assigning float to loat*

6) p=rootbeer;

valid, assigning adress of rootbear to p.

b) Program has an error, wrong return statement, if that is fixed

8 8
4 4
0 0
2 2