Question

c++ char* Ptr; // Ptr is at location 202 char a[10] = "Good luck"; // string[0]...

c++

char* Ptr; // Ptr is at location 202

char a[10] = "Good luck"; // string[0] is at location 300

Ptr = a;

cout<<*Ptr;

cout<<&a[2];

I wonder what the above two output values will look like, and why.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:
--------
G302

Explanation:
---------------
a is "Good luck"

cout << *ptr;
ptr points to first character of a. so, *ptr is G
so, cout << *ptr; prints G

cout<<&a[2];
as mentioned in question, a[0] is at location 300
so, a[1] is at location 301, a[2] is at location 302
so, &a[2] is address of location a[2] which is 302
so, cout<<&a[2]; prints 302

since endl is not used, there will not be a new line printed between G and 302
Add a comment
Know the answer?
Add Answer to:
c++ char* Ptr; // Ptr is at location 202 char a[10] = "Good luck"; // string[0]...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ question 1. C++ string Class What does the output look like after executing the following...

    c++ question 1. C++ string Class What does the output look like after executing the following statements? std::string numstr = "12"; numstr += "3"; std::cout << numstr << '\n'; A. None of these. B. The snippet has syntax errors. C. 15 D.123 // 2. Let S be a class that allows integers to be stored in its objects like an array. For example, if obj is an object of S, one can write statements like obj[0] = 100; or int...

  • 2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics...

    2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop....

  • What will the following code printout? void Function(int *ptr) { *ptr = 11; } // In...

    What will the following code printout? void Function(int *ptr) { *ptr = 11; } // In Main... int values[] = {4, 10, 6, 12, 8, 14}; int *p = &values[4]; Function(p); for(int i = 2; i < 5; i++) cout << values[i] << ' '; a) 6 12 8 14 b) 6 12 8 c) 4 10 6 11 8 14 d) 6 12 11 e) 6 12 11 14 I know the answer is D, but I do not...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str);...

    #include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() {    char string[100];    char inputChoice, choice[2];    int vowelTotal, consonantTotal;    //Input a string    cout << "Enter a string: " << endl;    cin.getline(string, 100);       do    {        //Displays the Menu        cout << "   (A) Count the number of vowels in the string"<<endl;        cout << "   (B) Count...

  • 1. Please answer a-d, there was a previous post with additional questions. Thank you in advance....

    1. Please answer a-d, there was a previous post with additional questions. Thank you in advance. Consider the following program and provide code and explanations where asked in the code comment after running the program in your system. Note that there are 4 parts (in bold) that need to be addressed. #include <iostream> #include <string.h> using namespace std; class Header{ private:     char used;     int payloadsize;     char* data; public:     Header (){         used = 0, payloadsize = -1, data = NULL;     }...

  • In C. // Extract the integer from the input string and convert to int int convert(char...

    In C. // Extract the integer from the input string and convert to int int convert(char *input){ // Declare int for result extracted from input int res = 0; // Declare int for sign of result // Declare two iterators // Declare a buffer for numeric chars // Set error to zero - no error found yet // Check for space in element 1 // Check for negative integer at element 2 // Loop to copy all numeric chars to...

  • Use the code below to answer the questions that follow. Assume that all proper libraries and...

    Use the code below to answer the questions that follow. Assume that all proper libraries and name spaces are included and that the code will compile without error. Within the main function, for the variable int last_sid , write in the last digit of your SMC student ID. int foo(int a, int b) { //First int c = a+b; while(c>=3) c-=3; return c; } //------------------------------------ char foo(string a, int b) { //Second return a[b]; } //------------------------------------ string foo(int b, string...

  • Memory Consider a process running the following program #include estdlib.h> #include #define const char* int int...

    Memory Consider a process running the following program #include estdlib.h> #include #define const char* int int <stdio.h> TO PRINT toPrintCPtr "Good luck!" TO PRINT; main for (i -0; i < sizeof (TO PRINT)-1; i++) printf("%c %c\n", toPrintCPt r [1], toupper(toPrintCPt r [i])); return(EXIT SUCCESS); Please tell where the following objects are stored in memory. Your choices are a. ROM BIOS b. kernal Memory (the OS) c. shared library memory (the glibc library) d. .text segment e. .rodata segment f. .data...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT