c++ - how print an array row with pointers -



c++ - how print an array row with pointers -

#include <iostream> #include <fstream> #include <string> using namespace std; int main(){ ifstream fin("c:\\users\\rati\\desktop\\iris_flower.txt"); float s=0; int x,n=5,m=150,i,j;float d[5]={0}; float **iris; float ss=n; iris=new float *[n]; for(i=0;i<n;i++) iris[i]=new float [m]; for(i=0;i<n;i++) for(j=0;j<m;j++) fin>> iris[i][j]; for(i=0;i<n;i++){ for(j=0;j<m;j++) cout<<iris[i][j]<<" "; cout<<endl; } for(j=0;j<m;j++){ for(i=0;i<n;i++) s+=iris[i][j]; d[j]+=s/ss; cout<<s<<endl; } scheme ("pause"); }

this total code. want print row 2d array pointer(no loops).i hope can write fragment add together did want

you can modify array pointers if want print array, have utilize loops.

check out example:-

int main() { int n = 3, m = 4, a[n][m], i, j, (* p)[m] = a; (i = 0; < n; i++) (j = 0; j < m; j++) a[i][j] = 1; p++; (*p)[2] = 9; homecoming 0;}

here

p pointer 4-element int arrays (i.e. pointer pointer int, first dimension 4 , sec unknown). when increment p, points next 4-element int array, i.e. 5th int altogether. p dereferenced offset 2, means 7th int changes, get

1 1 1 1 1 1 9 1 1 1 1 1

for converting integer array pointed p string, seek :-

string int_array_to_string(int *p, int size_of_array){ string returnstring = ""; (int temp = 0; temp < size_of_array; temp++) returnstring += itoa((* p)[temp]); homecoming returnstring; }

you row array here.

c++ arrays pointers

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -