Question

One way of obtaining a pointer to a variable is by writing something like: line 1:...

One way of obtaining a pointer to a variable is by writing something like:

line 1: int a, *p;

line 2: p = &a;

Another way of doing this is to write something like:

line 3: int *t = new int;

This allocates a memory location to which the variable t will point.

Write a function that includes the 3 lines of code above and returns the size of the memory location occupied by variable t. First, discuss how to write the function in your group then write the function and the matching main function. The function signature is:

int size_of_variable_star_t() ;
0 0
Add a comment Improve this question Transcribed image text
Answer #1
int size_of_variable_star_t(){
    int a, *p;
    p = &a;
    int *t = new int;
    return sizeof(t);
}

Note: Please comment below if you have any doubts

Add a comment
Know the answer?
Add Answer to:
One way of obtaining a pointer to a variable is by writing something like: line 1:...
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
  • Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and...

    Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and places that value into the variable number. The pointer gPointer will have been declared and set to point to a value before your code runs. Your code will be placed inside the main function with all the appropriate #includes. After your code runs, the test case will execute the following code: cout << "number = " << number << endl; For example: Test Result...

  • TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes...

    TRUE/FALSE 1. If pl is an integer pointer variable, with the value of 1000, pl++ changes P1 to point to the memory location 1001. ANSWER: T 2. When you return a dynamic array to the freestore, you must include the number of elements in the array 3. You can assign an array to a pointer variable. 4. The size of dynamic arrays must be declared at compile time. 5. int *pl; declares a static variable. ANSWER: F ANSWER: F ANSWER:...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • Please answer this question (JAVA) Consider now the following code fragment: 1 public class Main public...

    Please answer this question (JAVA) Consider now the following code fragment: 1 public class Main public static void main(String args) Person p; 2 3 pnew Person [2]; for (int i 0; i < p.length; i++) 3 пеw Person("A", "B", "С"); System.out.println(p [0].toString ()); 5 plil 6 8 9 10 6. What is the value of 'p' after line 3? (a) Something like "Person@42gf32" (b) null (c) A memory location 7. What is the value of 'p' after line 4? (a)...

  • C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point...

    C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...

  • In c++ The iron-puzzle.ppm image is a puzzle; it contains an image of something famous, howeve...

    In c++ The iron-puzzle.ppm image is a puzzle; it contains an image of something famous, however the image has been distorted. The famous object is in the red values, however the red values have all been divided by 10, so they are too small by a factor of 10. The blue and green values are all just meaningless random values ("noise") added to obscure the real image. If you were to create a grayscale image out of just the red...

  • c++ only. Please read directions. I'm looking to have each line re-written in a way that...

    c++ only. Please read directions. I'm looking to have each line re-written in a way that shows we're using the walk through method that the pointer is shifting by each value to solve this. Example far below shows what not to do.   Rewrite this program and remove the variable declared at line A below. Make your revised program generate the exact same output as the original without using the variable declared at line A. #include <iostream> using namespace std; int...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless...

    Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless it asking for. /* Write a program designed to get ages and heights from the user, then find the average age, average height, and average age/height ratio. */ #include <stdlib.h> #include <stdio.h> #define MAXNUM 50 typedef struct person { int age; double height; } Person; int getData(Person people[], int max) /* Get the data from the user and put it in an array of...

  • C Question: I apologize for this long size post, but I wanted to explain the way...

    C Question: I apologize for this long size post, but I wanted to explain the way of doing it. Kindly HELP me . Question is: implement char *mystrcat(char *dest, const char*src)   adds a copy of the string src onto the end of the string starting at dest. The first char is src is put at the location of the 0 at the end of string dest. Returns dest Could you please implement / write the code in the same way...

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
ADVERTISEMENT