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

  • QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2,...

    QUESTION 9 What will be the output of following code snippet? int a[3] = {1, 2, 3};         int *p = a;         int **r = &p;         printf("%p %p", *r, a); A. Different memory addresses printed B. 1 2 C. Same memory address printed twice D. 1 1 2 points    QUESTION 10 What will be the output of following code snippet? int arr[4] = {1, 2, 3, 4};         int *p;         p = arr + 3;         *p = 5;         printf("%d\n", arr[3]); 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...

  • please explain [5 pts] What is the outcome of compiling and executing the following code. Assume...

    please explain [5 pts] What is the outcome of compiling and executing the following code. Assume it is embedded in an otherwise correct and complete C++ program void printBackwards(int *arr, int len){ if (len <=0) return; cout< } int main(){ int arr[4] = {1, 2, 3, 4}; printBackwards(arr, 4); } [10 pts] Implement a function that returns the minimum value in an integer array ​‘arr’​ of length ‘len’​. You MUST use a RECURSIVE solution. //Precondition: An integer array with length...

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

  • IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer...

    IN C PROGRAMMING, NOT C++ 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...

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