Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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 variable

Explanation / 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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote