Introduction to Pointers. Simple C++ Coding, please make sure it compiles :) The
ID: 3778409 • Letter: I
Question
Introduction to Pointers. Simple C++ Coding, please make sure it compiles :)
The following program contains missing code. You are to fill in the missing code by (1) declaring pointers for the corresponding variables (that are not yet pointing to anything); (2) assign the pointer variables that you just declared to the address for the corresponding variable (i.e make the integer pointer variable point to the integer variable); and (3) assign arbitrary values of your own choosing to the pointer variables themselves (note that you should not assign anything directly to num, ch, and val, but instead to the pointers). include kiostream using namespace std; int main() int num; char ch float val;Explanation / Answer
Please follow the code and comments for description :
CODE :
#include <iostream>
#include <cstddef>
using namespace std;
int main()
{
int num; // actual variables declaration
char ch;
float val;
int *ip = NULL; // pointer variable
char *cp = NULL;
float *fp = NULL;
ip = # // point the pointers to the corresponding variables
cp = &ch;
fp = &val;
*ip = 25; // assign values to the pointers but not to the variables
*cp = 'M';
*fp = 0.25;
cout << "num is : " << num << endl; // print the data to console
cout << "ch is : " << ch << endl;
cout << "val is : " << val << endl;
return 0;
}
OUTPUT :
num is : 25
ch is : M
val is : 0.25
Hope this is helpful.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.