Give the output of the following code. int *pt; int a[10]={10, 11,12, 13, 14,15}
ID: 3692472 • Letter: G
Question
Give the output of the following code. int *pt; int a[10]={10, 11,12, 13, 14,15}; pt = ampa[2]; cout lessthan lessthan * pt lessthan lessthan endl; pt = pt + 3; cout lessthan lessthan * pt lessthan lessthan endl; pt = pt + 3; cout lessthan lessthan * pt lessthan lessthan endl; pt--; cout lessthan lessthan * pt lessthan lessthan endl; The following statement declare an integer array: int a[5] = {3,6,4,1,8}; Write the output for the following code. cout lessthan lessthan * (a + 2); cout lessthan lessthan amp a[3] - a; int *p = a + 2; cout lessthan lessthan ++ * (--.p);Explanation / Answer
Solution.cpp
#include <iostream>//header file for input utput function
using namespace std;//it tells the compiler to link std namespace
int main()
{
int *pt;//pointer variable
int a[10]{10,11,12,13,14,15};
pt=&a[2];//address location at pt
cout<<*pt<<endl;//accessing pt variable at address location at &a[2]
pt=pt+3;//adding 3 to pt variable
cout<<*pt<<endl;
pt--;//decrementing 1 to ptr variable
cout<<*pt<<endl;
return 0;
}
output
12
15
14
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.