1. Write the following programs then try to understand and write down the output: void main() { int n = 500; int* p = &n

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1. Write the following programs then try to understand and write down the output: void main() { int n = 500; int* p = &n

Post by answerhappygod »

1 Write The Following Programs Then Try To Understand And Write Down The Output Void Main Int N 500 Int P N 1
1 Write The Following Programs Then Try To Understand And Write Down The Output Void Main Int N 500 Int P N 1 (112.56 KiB) Viewed 62 times
1. Write the following programs then try to understand and write down the output: void main() { int n = 500; int* p = &n; cout<<"n: "<<n<<endl; cout<<"*p: "<<*p<<endl; cout<<"p: "<<p<<endl; cout<<"&n: "<<&n<<endl; (*p)++; int j=5; p=&j; cout<<"The pointer now points to y variable and its value is :"<<*p<<endl; *p = 20; cout<<"n value is "<<n<<endl<<"j value is "<<j«<endl; int main() { intalpha = 5; intbeta = 20; int* alphaptr = &alpha; int* betaPtr = &beta; cout<< "Manipulating alpha through alphaptr" <<endl; cout<<< "Before: alpha= " << alpha <<endl; cout<< "Adding 5 to value pointed to by alphaptr" <<endl; *alphaPtr += 5; cout<< "After: alpha= " << alpha <<endl; cout<< "\nPrinting beta through betaptr" <<endl; cout<< "Value pointed to by betaptr: " « *betaPtr<<endl; cout<< "Adding 5 to beta" <<endl; beta += 5; cout<< "Value pointed to by betaptr: " << *betaPtr<<endl; return 0; } Pointers and Arrays: Rewrite the following program to use pointers instead of arrays in two ways: (1) Use pointer operators that do not modify the pointer to process the array. You can use the array name as the pointer, or you can define a constant pointer and make to the array (i.e. array's first element).

Pointers and Arrays: Rewrite the following program to use pointers instead of arrays in two ways: (1) Use pointer operators that do not modify the pointer to process the array. You can either use the array name as the pointer, or you can define a constant pointer and make it point to the array (i.e. array's first element). (2) Use pointer operators that modify the pointer to process the array. You should first define a non-constant pointer and make it point to the array. int main() { int a[5]; for (int i=0;i<5;++i) { cout<<"array element: "; cin>>a; } for (int i=0;i<5; ++i) a=a*10; for(int i=0;i<5; i++) cout<<a<<" "; return 0; } 2/2
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply