Build a program that performs the following operations: Declares three pointer v
ID: 3797861 • Letter: B
Question
Build a program that performs the following operations: Declares three pointer variables called I Ptr of type int, cPtr of type char, and f Float of type float Declares three new variables called I Number of int type, f Number of float type, and c Character of char type Assigns the address of each nonpointer variable to the matching pointer variable Prints the value of each nonpointer variable Prints the value of each pointer variable Prints the address of each nonpointer variable Prints the address of each pointer variableExplanation / Answer
#include <iostream>
using namespace std;
int main()
{
// Pointer declaration
int *iPtr;
float *fFloat;
char *cPtr;
//Variable Declaration
int iNumber;
float fNumber;
char cCharacter;
//Assigning Pointer to a variable
iPtr = &iNumber;
fFloat = &fNumber;
cPtr = &cCharacter;
cout << iNumber << " " << fNumber << " " << cCharacter << endl;
cout << iPtr << " " << fFloat << " " << cPtr << endl;
cout << &iNumber << " " << &fNumber << " " << &cCharacter << endl;
cout << &iPtr << " " << &fFloat << " " << &cPtr << endl;
return 0;
}
Output
0 0 0x7ffd19c46324 0x7ffd19c46320 0x7ffd19c46324 0x7ffd19c46320 0x7ffd19c46338 0x7ffd19c46330 0x7ffd19c46328
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.