C++ Programing help: This is theory not complete code. Consider the following co
ID: 3859883 • Letter: C
Question
C++ Programing help: This is theory not complete code. Consider the following code. What would be the output of the program?
#include <iostream>
#include <string>
using namespace std;
typedef struct
{
char szFirstName[16];
char szLastName[16];
char szMiddleName[16];
int nAge;
} CONTACT;
int main(int argc, char *argv[], char *envp[])
{
char szBuffer[1024];
CONTACT * pContact = (CONTACT *)1000;
pContact++;
sprintf_s(szBuffer, sizeof(szBuffer), "Address: 0x%08X", (long)pContact);
cout << szBuffer << endl;
return 0;
}
Explanation / Answer
Ans) Address: 0x0000041C
Explanation:
The program allocates a memory of 1000 structure records of CONTACT and creates a pointer pContact for it. Then the address of pContact is incremented and the location of address is printed in hexadecimal format into the szBuffer variable which is 0x0000041C
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.