Question

1. declare two integer variables x and y and two pointers to p and q. initialize...

1. declare two integer variables x and y and two pointers to p and q. initialize the value of x with 2, y with 8 and the pointer p should point to the address of x and q should point to the address of y. 2. then write a C statements that will print the following information:

a. the address of x and the value of y.

b. the value of p and the value of *p.

c. the address of y and the value of y.

d. the value of q and the value of *q.

e. the address of p (not its contents).

f. the address of q ( not its contents).

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

#include<stdio.h>
int main()
{
   //declaring varibles
   int x,y;
   int *p,*q;
  
   x=2;
   y=8;
   p=&x;//p points to the address of x
   q=&y;//q points to the address of y.
  
  
   //a
   printf("address of x :%u\nvalue of y:%d\n",&x,y);
   //b
   printf("value of p :%u\nvalue of *p:%d\n",p,*p);
   //c
   printf("address of y :%u\nvalue of y:%d\n",&y,y);
   //d
   printf("value of q :%u\nvalue of *q:%d\n",q,*q);
   //e
   printf("address of p:%u\n",&p);
   //f
   printf("address of q:%u\n",&q);
  
   return 0;
}

output:

address of x :6487644
value of y:8
value of p :6487644
value of *p:2
address of y :6487640
value of y:8
value of q :6487640
value of *q:8
address of p:6487632
address of q:6487624


Process exited normally.
Press any key to continue . . .

Add a comment
Know the answer?
Add Answer to:
1. declare two integer variables x and y and two pointers to p and q. initialize...
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
  • Lab 8 CS102 Lab 8 Hands on programming with Pointers The goal of this lab exercise...

    Lab 8 CS102 Lab 8 Hands on programming with Pointers The goal of this lab exercise is to apply the knowledge of pointers and File input output operations. Program 1 Short description: Declare, initialize and use pointers for different data types. Detailed Description: Declare 4 variables of type's int, float, double and char respectively and initialize them to some logically correct values. Declare pointers to all these variables. Initialize the pointers to point to these variables respectively Print the values...

  • Please code in c 1. Write a program which does the following: Declare and initialize three...

    Please code in c 1. Write a program which does the following: Declare and initialize three pointers. One points to an integer, one points to a float and one points to a character variable Ask the user to enter appropriate values for these variables. Output the values to the screen by accessing the variables directly and then by using pointer references. Print the address of each variable. Modify the variables by performing any arithmetic operation only using pointer refer- ences...

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

  • 1) Declare and initialize a pointer px to an integer variable x with the initialized value...

    1) Declare and initialize a pointer px to an integer variable x with the initialized value 3. Consider two cases of the value of x allocate on (a) the stack memory (b) the heap memory 2) Write a comment on each instruction down below and provide a memory diagram for heap and stack to illustrate these statements. int* iptr = new int[5]; // int* iptr_1 = new int(5); //

  • Write a complete program that: 1) declares two local integers x and y 2) defines a...

    Write a complete program that: 1) declares two local integers x and y 2) defines a global structure containing two pointers (xptr,yptr) and an integer (z) 3) Declares a variable (mst) by the type of previous structure 4) requests the values of x and y from the user using only one scanf statement 5) sets the first pointer in the struct to point to x 6) sets the second pointer in the struct to point to y 7) uses the...

  • 8) Write the Java code to Declare an Integer Number and Initialize it to value 10....

    8) Write the Java code to Declare an Integer Number and Initialize it to value 10. Then use Ternary Operator to Check if the Integer Number is Odd or Even and print out the Result Odd or Even.

  • (15 pts) Using the following example, int a, p=&a; *p = 20; Give the two major...

    (15 pts) Using the following example, int a, p=&a; *p = 20; Give the two major differences of * and & in the above example. (35 pts) Do the following in a program segment step by step. The next step uses the results of the previous step and earlier, using a single statement only and none for manual work. Declare an array called a of float of size 10 and initialize it to 2.5, -3.3, 5.9, 1.0, 3.5, 4.3, -7.3,...

  • Create 3 variables, (int, chart and float) and give give each of them some value. Print...

    Create 3 variables, (int, chart and float) and give give each of them some value. Print out the values. Then create a pointer for each variable and initialize the pointers. Then make them point to the memory address of the corresponding variables. Print out the pointers (=memory addresses where the pointers point to, use %p). Finally, print out the values that are in the memory locations where the pointers point to(so print out the values using the pointers, not 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...

  • Write a complete C program that does the following: . o Declare a and b as...

    Write a complete C program that does the following: . o Declare a and b as character variables. Initialize a to this value: 127 o Declare c as an unsigned character variable o Multiply a by 2 and store the result in variable b. o Multiple a by 2 and store the result in variable c. Print the values of a, b, and c. Use the %d specifier in each case. Declare d as an integer variable. Initialize d to...

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