Question

in C++ int x = 5 create a reference “a” equal to x and output a....

in C++

int x = 5

create a reference “a” equal to x and output a.

create a pointer (address type) “b” and output b

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

For your question i have given code and explained in the line by line comment.

Screenshots of codes are all attached, kindly follow all for better understanding.

code ..

#include<iostream>
using namespace std;

int main()
{
   int x=5; // declaring x=5;

   int &a=x; // creating refernce of x which will store memoey address of x

   cout<<a<<endl; // printing using reference

   int *b=&x; // creating pointer ot the x and assign address of x
               // as pointers point to a particular memory address
   cout<<*b<<endl; // printing using pointer

   return 0;
}

/* after running this program you will get
   5
   5
   as output
*/

Add a comment
Know the answer?
Add Answer to:
in C++ int x = 5 create a reference “a” equal to x and output a....
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
  • 4. Consider the following declarations: I. const int* x I. const int const x II. int...

    4. Consider the following declarations: I. const int* x I. const int const x II. int const x; IV. int x V. int x Match declarations I-V with the following: (a) the integer it points to can change in value. A pointer to an integer that can never change the address it points to, but (b) A pointer to a pointer to an integer A pointer whose address can never change, and whose integer value that (c) it points to...

  • -Create a function output() in C that takes the pointer to the array and its size...

    -Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (malloc format) (function prototype : void output(int *arrayPtr, int size); -Create a function check() in C that takes the pointer to the array and a number and checks if the number is in the array. If the number is in the array, returns the index of the element of the array holding the number. Otherwise, returns -1.

  • What will be the output of the following code int x = 5; int y =...

    What will be the output of the following code int x = 5; int y = 2; f(x,y); printf(“%s \n”, (x/y > 2) ? “x is more than two times larger than y” : “x is less than or equal to 2*y\n ”); f(int x, int y) { x = 2*y; printf(“%s \n”, (x/y > 2) ? “x is more than two times larger than y” : “x is less than or equal to 2*y \n”); } a. x is...

  • A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points...

    A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points to pointer Please code an Ivalue reference to reference *pointer Please code an rvalue reference to reference *pointer Please use what you created, if legal, to change the value of cs to 413. Provide your code or reasoning: A.5 5 pts int cs 340 int *pointer &cs; Please code a constant pointer which points to pointer Please code an Ivalue reference to reference *pointer...

  • Create the program in C++ please. The new operator as outlined in 10.9 . Create a...

    Create the program in C++ please. The new operator as outlined in 10.9 . Create a Test class that includes the following Data members • First Name, last name, test1, test2, test3 o Methods • Accessor methods for each of the data members' • Mutator methods for each of the data members . A Default Constructor . A constructor that will accept arguments for each of the 5 data members • A method that will calculate the average of the...

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

  • Question 1 What is the value of x after the following int x = 5; x++;...

    Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • C Programming What is the output of the following code? int x=5: x * = 3:...

    C Programming What is the output of the following code? int x=5: x * = 3: printf("%d\n", x): x++: ++x: x = x/2: printf("%d\n", x): printf("%d\n", x++): printf("%d\n", ++x);

  • 12. What is the output of the following C++ code? int x; int y; int *p...

    12. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl; 13. What is the output of the following C++ code? int x; int y; int *p = &x; int *q = &y; x = 35; y = 46; p...

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