1.Explain the pointer data type and pointer variables 2.Use the address of opera
ID: 3789692 • Letter: 1
Question
1.Explain the pointer data type and pointer variables
2.Use the address of operator and the dereferencing operator to manipulate dynamic variables
3. Explain how pointer arithmetic is related to the manipulation of arrays
Respond to item 1 above using one descriptive paragraph; be short and to the point.
Respond to item 2 above by way of two examples, be short and to the point
Respond to item 3 above by way of two examples, be short and to the point
c++
textbook: c++ from control structures through objects 8th edition.
chapter 9: pointers
Explanation / Answer
pointers: A Pointer is a variable that holds the adress of another varaible.it is a derived data type utilized to acess data and manipulating data stored in memory.
pointers are much efficient in handling arrays.And aclso utilized for manipulating the data structures like stack,queues,linked list..etc.Reduces the length and complexity of a programm,but increases the speed of execution in a programm.
Address operator:To obtain the adress of a variable ,a pointer is alloted which was indicated by the symbol ampersand i.e & .it is placed before the variable.
Syntax data type *pointer name
Examples int &p;
float &q
Dereferencing operator: this operator is utilized to obtain the variable tapered to with a pointer .Also while declaring the pointer types.i.e *
Syntax data type * pointername
Example int *x;
float *y;
Example programm for the pointers
#include<iostream>
void swap (int *a, int *b);
main()
{
int x,y;
cout<<"Enter the values of &x,&y: " ;
cin("%d %d", &x,&y);
swap(&x,&y);
cout<<"x=%d,y=%d", x,y <<end1;
}
void swap(int *a, int*b)
{
int t;
t=*a;
*a=*b;
*b=t;
cout<<"after swaping the values a and b are a=%d ,b=%d", *a,*b: " ;
cout<< swaping<<end1;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.