1.) How to declare and initialize the pointer to an array of integers ?
There is error in 2nd line after main() : scalar obj array requires one element in initializer .
Below is my attempt :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include<iostream>
usingnamespace std ;
int main () {
char *str = "Raman" ;
int (*arr)[5] = {1,2,3,4,5};
for (int i=0 ; i<5 ; i++) {
cout <<"\n"<< *(str+i)<<"\t"<<((void*)str+i) ;
}
for (int i=0 ; i<5 ; i++) {
cout <<"\n"<< *(arr+i)<<"\t"<<(arr+i);
}
return 0 ;
}
The short answer is it can't be done. In order for your pointer to point to anything you have to have an array for it to point to. You can't make it point to a temporary array. It'd be like trying to do something like this: