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

1. Answer the following C program questions: A) What will this program print wit

ID: 3818543 • Letter: 1

Question

1. Answer the following C program questions:

A) 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;

}

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

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

a)

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

pnum++;

++pnum;

printf ("%d ", *pnum);

b)

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

A) Program has a compilation issue (if we fix it i.e., return instead of rerturn)

8 8
4 4
0 0
2 2

B)

In question (A), ref is the address of what? first element in array. i.e., 8

What about ref +1? It is element next to element pointed by ref 1 i.e., 4

What does ++ref point to? This is not allowed, you can not modify ref.

C)

a) program will output 5 .

Reason: pnum initially pointed to 3rd element in array (value 3), tthen pnum location is incremented and it points to 4 and then again it is incremented and it points to 5.

b)

This will print 2,1,0

p is pointing to first element which is 2nd element (in printf expressions ar eevaluated righ to left so P is incremneted

*(p+1) means second element which is changed to 0