Philips Interview Report
- 0of 0 votes
AnswerCopy the following program into ptr3.c.
- stimulation101 March 04, 2017 in England
#include <stdio.h>
int main()
{
int i, j;
int * p, * q;
int ** x;
i = 100;
j = 200;
p = &i;
q = &j;
x = &p;
*p = *p + *q;
*q = **x / 2;
**x = *p + j;
printf(" i = %d\n", i);
printf("&i = %p\n", &i);
printf(" j = %d\n", j);
printf("&j = %p\n", &j);
printf(" p = %p\n", p);
printf("&p = %p\n", &p);
printf("*p = %d\n", *p);
printf(" q = %p\n", q);
printf("&q = %p\n", &q);
printf("*q = %d\n", *q);
printf(" x = %p\n", x);
printf("&x = %p\n", &x);
printf("*x = %p\n", *x);
printf("**x= %d\n", **x);
return 0;
}
Study this code carefully and make sure you understand how the program works. Then modify the program by adding a new variable that stores the address of x. Then use your variable to update (indirectly) the value of i and then print out the new value to demonstrate that your modification has worked.| Report Duplicate | Flag | PURGE
Philips Junior programmer - 0of 0 votes
AnswersCreate a text file called calc.c that contains the following C program:
- stimulation101 March 04, 2017 in England
#include <stdio.h>
float add (float x, float y)
{
return x + y;
}
int main()
{
float a, b, r;
char op;
do {
printf("number op number? ");
scanf(" %f %c %f", &a, &op, &b);
switch (op)
{
case '+' : r = add(a,b);
break;
case 'q' : break;
default : op='?';
}
if (op=='?')
printf("Unknown operator\n");
else if (op=='q')
printf("Bye\n");
else
printf("%f %c %f = %f\n", a, op, b, r);
}
while (op != 'q');
return 0;
}
The program behaves like a calculator asking the user to type in binary expressions (like 2.5 + 3.7) and printing out the results. If the user enters 'q' for the operator (e.g. 0 q 0) then this is taken as a signal to stop the program.
Add a new function to the program that multiplies its two arguments together and returns their product. Then modify the switch statement so that the operator '*' causes this new product function to be called. Test the program by using a mixture of '+' and '*' calculations.
Add operators for subtraction ('-') and division ('/') and test your program again.
We introduce some special operators. Write functions to implement each of these (adding one at a time and testing after each new operator is incorporated into your calculator).
Symbol Description Example
m Minimum 2.3 m 1.7 = 1.7
M Maximum 2.3 M 1.7 = 2.3| Report Duplicate | Flag | PURGE
Philips Junior programmer Programmin in c