- Write a function alter with two parms passed by reference: x and y. alter changes the value of x to x+y and changes the value of y to x*y. Write a main function to read in two integers, print the two integers, call the function alter using the two integers as parameters, and print the two integers again after the call to alter.
- Show what is printed by the following program:
main()
{
char a = 'x', b = 'y';
void func1(char,char);
void func2(char *,char *);
func1(a,b);
printf("a = %c b = %c\n",a,b);
func2(&a,&b);
printf("a = %c b = %c\n",a,b);
}
void func1(char a, char b)
{
a = 'p';
b = 'q';
}
void func2(char *a, char *b)
{
*a = 'p';
*b = 'q';
}
- Assume that the variables declared below are stored at the following locations. Show what value is stored as a result of each of the following statements. Assume that each statement uses the values stored by the previous statements.
int *p, *q, *r;
int a = 10; b = 25;
int c[4] = {6,12,18,24};
address variables
5000 p
5004 q
5008 r
500C a
5010 b
5014 c[0]
5018 c[1]
501C c[2]
5020 c[3]
- p = c;
- q = &a;
- r = p + 2;
- c[1] = *p;
- c[2] = *(p + 2);
- c[3] = *p + 2;
- *r = *q;
- r = q;
- p = &c[0];
- p++;
Change the following array references to equivalent pointer references:
- p[2]
- p[2]++
- &p[3]
- ++p[2]