Question

2. Write a program to print the following output using pointer arithmetic. Sample Outpit: Address p is 4586052 Size of integer is 4 bytes. Address p+1 is 4586056
0 0
Add a comment Improve this question Transcribed image text
Answer #1

below i written complete C code as per the requirement.

Please note the below program has been tested on ubuntu 16.04 system and compiled using gcc compiler. This code will also work on code blocks and visual studio.

-----------------------------------------------------------------------------------------------------------------------------------

Program:

------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

int main()

{

long int address = 4586052;
long int *p;

p = &address;

printf("Address of p is %ld\n", *p);

printf("Size of integer is %ld bytes.\n", sizeof(int));

printf("Address of p+1 is %ld\n", *p+4);

return 0;

}


===============================================================

Sample Output:

nirmalsharma@ubuntu:~/HomeworkLib solutions$ gcc pointer_arithmetic.c nirmalsharma@ubuntu: /HomeworkLib solutionss ./a.out Address of p i

================================================================

Kindly Check and Verify Thanks..!!!

Add a comment
Know the answer?
Add Answer to:
2. Write a program to print the following output using pointer arithmetic. Sample Outpit: Address p...
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
  • Pointer tasks: ( In C++ ) 1. Write a program to store the address of a...

    Pointer tasks: ( In C++ ) 1. Write a program to store the address of a character variable and a float variable. • Print the address of both variables. • Print the values of variable using dereference operator. • Add 2 in float value using pointer. • Print address of character variable using reference operator. 2. Write a program that takes 5 elements in an array and print them in reverse order using pointers. 3. Write to program that takes...

  • please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function...

    please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...

  • C++ What is the output of the following program? Using a pointer diagram show the evolution...

    C++ What is the output of the following program? Using a pointer diagram show the evolution of all data objects in memory. Assume the code is embedded in a correct and complete program. 3.(8 pts) What is the output of the following program? Using a pointer diagram show the evolution of all data objects in memory. Assume the code is embedded in a correct and complete program. int array size 4, *a i a new int [array size] int *p...

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

  • Some pointer arithmetic is allowed. Which of the following arithmetic operators is allowed? (can have multiple...

    Some pointer arithmetic is allowed. Which of the following arithmetic operators is allowed? (can have multiple answers) a) pointer + integer b) pointer - pointer c) pointer - integer d) integer + pointer e) integer * pointer Which statement correctly defines a vector object for holding Dealer objects? a.Dealer vector v; b.Dealer<vector> v; c.vector<Dealer> v; d.vector v<Dealer>; One of the following statements dynamically allocates an array of floats having size SIZE. a.float array; b.float *array[SIZE]; c.float array = new float[SIZE];...

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

  • 1. Write a C++ Program to display address of elements of an array using both array...

    1. Write a C++ Program to display address of elements of an array using both array and pointers 2. Write a C++ Program to insert and display data entered by using pointer notation. 3. Write a C++ Program to access Array Elements Using Pointer

  • solve it in c+* Part II: Dynamic Arrays and Pointer Arithmetic Q5: Implement a subset function...

    solve it in c+* Part II: Dynamic Arrays and Pointer Arithmetic Q5: Implement a subset function for a dynamic array which returns a new dynamic array that is a subset of the original. (15pt) input parameters: array - (the array and any related parameters) start - index of the first element end - index of the last element This function returns a new dynamic array containing the elements from the start thru the end indices of the original array. All...

  • Can someone help me with these C program problems? Thanks 1. Write a C program that...

    Can someone help me with these C program problems? Thanks 1. Write a C program that creates two arrays of integers, one on the stack and one on the heap. You will loop through these arrays and populate them with values (any value is fine). You will then loop through these arrays again and print each value. Your output should look something like “Value in index 1 is 100 from stack array and 100 from heap array.” Do not forget...

  • 2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics...

    2. Pointer arithmetic: a) Write a printString function that prints a string (char-by-char) using pointer arithmetics and dereferencing. b) Write a function “void computeMinMax(double arr[], int length, double * min, double * max)” that finds the minimum and the maximum values in an array and stores the result in min and max. You are only allowed to use a single for loop in the function (no while loops). Find both the min and the max using the same for loop....

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