Question

For each of the following, write a single statement that performs the indicated task. Assume that...

For each of the following, write a single statement that performs the indicated task. Assume that short integer variables value1 and value2 have been defined and that value1 has been initialized to 70000. a) Define the variable lPtr to be a pointer to an object of type short.

b) Assign the address of variable value1 to pointer variable lPtr.

c) Print the value of the object pointed to by lPtr.

d) Assign the value of the object pointed to by lPtr to variable value2.

e) Print the value of value2.

f) Print the address of value1.

g) Print the address stored in lPtr. Is the value printed the same as the address of value1?

Homework Answers

Answer #1
a) Define the variable lPtr to be a pointer to an object of type short.
short* lPtr;

b) Assign the address of variable value1 to pointer variable lPtr.
lPtr = &value1;

c) Print the value of the object pointed to by lPtr.
printf("%d",*lPtr);

d) Assign the value of the object pointed to by lPtr to variable value2.
value2 = *lPtr;

e) Print the value of value2.
printf("%d",value2);

f) Print the address of value1.
printf("%u",&value2);

g) Print the address stored in lPtr. Is the value printed the same as the address of value1?
printf("%u",lPtr);
Know the answer?
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
Similar Questions
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their...
Leave comments on code describing what does what Objectives: 1. To introduce pointer variables and their relationship with arrays 2. To introduce the dereferencing operator 3. To introduce the concept of dynamic memory allocation A distinction must always be made between a memory location’s address and the data stored at that location. In this lab, we will look at addresses of variables and at special variables, called pointers, which hold these addresses. The address of a variable is given by...
JAVA Exercise_Pick a Card Write a program that simulates the action of picking of a card...
JAVA Exercise_Pick a Card Write a program that simulates the action of picking of a card from a deck of 52 cards. Your program will display the rank and suit of the card, such as “King of Diamonds” or “Ten of Clubs”. You will need: • To generate a random number between 0 and 51 • To define two String variables: a. The first String should be defined for the card Suit (“Spades”, “Hearts”, “Diamonds”, “Clubs”) b. The second String...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and...
1- Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values...
Question 1 Which statement is false about what Data Types defines Question 1 options: What values a variable cannot hold? How much memory will be reserved for the variable? What value a variable will hold? How the program will use the data type? Question 2 Using the structure below, which of the following statements about creating an array (size 20) of structures are not true? struct Employee{     string emp_id;     string emp_name;     string emp_sex; }; Question 2 options:...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
You can complete this assignment individually or as a group of two people. In this assignment...
You can complete this assignment individually or as a group of two people. In this assignment you will create a ​​Sorted Singly-Linked List​ that performs basic list operations using C++. This linked list should not allow duplicate elements. Elements of the list should be of type ‘ItemType’. ‘ItemType’ class should have a private integer variable with the name ‘value’. Elements in the linked list should be sorted in the ascending order according to this ‘value’ variable. You should create a...
The Galactic Federation of Planets (GFP) maintains records on all planets that are applying to become...
The Galactic Federation of Planets (GFP) maintains records on all planets that are applying to become members of the GFP. A planet may make an application to become a member of the Galactic Federation of Planets when their technology has led them to develop Star Gate technology enabling them to travel to other planets in the galaxy outside their own solar system. Your assignment is to create a class that can be used to hold the basic information about a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT