Question

A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points to pointer Please code an Ivalue reference

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

Please find the code below::

Gven code:

int cs = 340;
int *pointer = &cs;

//constant pointer is as below
int* const constPointer = &cs;

// a lvalue reference is as below
int& lvalueConst = *pointer;

// a rvalue reference - that is not possible

int&& *rvalueConst = *pointer; -> It will give compile time error because *pointer is lvaue and rvalue cannot be initiazed by lvalue.

The value of cs can be changed to 413 using the folllowing code.

*constPointer = 413;

Here the pointer is constant not the int , So value of cs can be changed.

Add a comment
Know the answer?
Add Answer to:
A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points...
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
  • For the Below question please write correct answer as it is asked. Thanks A.4 5 pts...

    For the Below question please write correct answer as it is asked. Thanks A.4 5 pts Please explain each parameter passing method, when to use it, and code a function prototype example Pass-by-lvalue-reference Pass-by-const-rvalue-reference A.4 5 pts Please explain each parameter passing method, when to use it, and code a function prototype example Pass-by-lvalue-reference Pass-by-const-rvalue-reference

  • A.2 5 pts - VWhat is a dangling/stale pointer? And please give code example [Yes ]No...

    A.2 5 pts - VWhat is a dangling/stale pointer? And please give code example [Yes ]No Does delete delete a pointer? Please explain why. Then please give instructions how to properly deallocate an object allocated on Free-Store. Please ample to demonstrate. use a code

  • Question 17 2 pts A pointer is: A keyword used to create variables A variable that...

    Question 17 2 pts A pointer is: A keyword used to create variables A variable that stores address of an instruction A variable that stores address of other variable A macro defined as a preprocessor directive. 2 pts Question 18 The operator used to get value at address stored in a pointer variable is: O& && O II Question 19 2 pts In the following code what is 'P: typedef char *charp; const charp P; Pis a constant Pis a...

  • Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank y...

    Code in c++ please. Does not have to be complete, just write code for the ones you know. Thank you. template <typename T> class smart_ptr { public: smart_ptr(); // Create a smart_ptr that is initialized to nullptr. The reference count // should be initialized to nullptr. explicit smart_ptr(T* raw_ptr); // Create a smart_ptr that is initialized to raw_ptr. The reference count // should be one. smart_ptr(const smart_ptr& rhs); // Copy construct a pointer from rhs. The reference count should be...

  • 2) (10 pts) Write a function that takes in a pointer to a linked list of...

    2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...

  • 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:...

  • Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as...

    Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...

  • Assume that arr[] is an array of 5 values. Write code within the FOR loop below...

    Assume that arr[] is an array of 5 values. Write code within the FOR loop below so that it finds the min value in the array. You MUST use the x pointer within the FOR loop. It is the only pointer you can use. You are not allowed to made additional function calls or modify anything else within the function. Do not modify the FOR loop conditions or anything outside of the FOR loop. You must use complete C++ code...

  • Question 2 (a) Provide a single line of C++ code that will declare a variable that...

    Question 2 (a) Provide a single line of C++ code that will declare a variable that points to a string value, the variable is named x. [2 marks] (b) You have array c declared as string *c [5]; Give the single line of C+ + code that will assign the string pointer stored in variable x (from above) to the third element of the array c. [2 marks] (c) Write a for loop that initialises the contents of each element...

  • Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...

    Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...

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