Hello again everyone! I am confused by the instructions given. Can someone help and teach how to do it? I have no experience in programming I hope you can help me. Thank you!
EDIT: It has to be in C language
TASK:
1.Given three integer variables, x= 512, y=1024,and z=2048, write a program to print out their left values as well as their right values.
2.Write a program to update the value of the double variable flt_num from 123.45 to 543.21 by using a double pointer.
3.Given character variable ch and ch= ‘A’ , write a program to update the value of ch to decimal 66 by using a pointer.
4.Given that x = 5 and y = 6, write a program to calculate the multiplication of the two integers and print out the result, which is saved in x,all in the way of indirection (that is using pointers)
1) this makes no sense. you need to ask your professor or review what was said in class.
I mean, the right of x = 512 is x, so cout << x and the left is 512 so cout << "512" but that is really silly to ask for and a weird way to say it.
2) double fit_num{123.45}; //make the variable
double * pfn = & fit_num; //get a pointer to it
*pfn = 543.21; //now cout fit_num, it is changed because you modified it from the pointer.
3) more or less the same as above, with a little twist. can you do it?
4) more of the same, get past 2 and this is just a little more.
Not yet :/ our professor didnt provide any notes and i dont have an idea how to write the program. Our professor didnt upload the file so i dont have any guides at all. Also the examples on the internet are not helping me
my C is a little rust, but maybe this will get you started:
1 2 3 4 5 6 7 8 9 10
#include <stdio.h>
int main()
{
int var =10; //an integer
int *p; // a pointer to an integer.
p = &var; //make p point to var.
*p= 42; //change the value of the integer that p points to (var).
printf("%i\n", var); //did var change? print it to see!
return 0;
}
In part 1, what does the prof mean by "left values" and "right values" Is it the address and the value as againtry has written? Or the left and right 8 bits of the value? Or something else?
How do I know I'm doing it right? What does it look like when you run it?
Your program should print the results of each task. For example, in task 2, you might print the value of flt_num after the update.