Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi
I get a number from dynamic array and then print, I can not.
What do I do?
input:2
3
3
0
0
5
1
2
3
 
code:
 
#include<iostream>
using namespace std;
void s(int f[],int d)
{
	cout<<"matris  element i,j   :\ni=";
        cin>>f[0,0];cout<<"j=";cin>>f[0,1];
        f[0,2]=d;
        cout<<"add number not 0 ";
	for(int k=1;k<d+1;k++)
	{   
		cout<<"\n array i="; cin>>f[k,0];
		cout<<"array j=";cin>>f[k,1];
		cout<<"value array ij=";cin>>f[k,2];
		cout<<f[k,2];
	}
	for(int i=1;i<d+1;i++)
	 {
		for(int j=0;j<3;j++)
		cout<<f[i,j];
	    cout<<"\n";
	 }
}
void main()
{
    int w;
	cout<<"number not 0 :";
	cin>>w;
    int *b=new int [w+1,3];
    s(b,w);
}
		  
	
 
Posted 20-Nov-12 10:16am
Edited 20-Nov-12 10:18am
v2
Comments
joshrduncan2012 at 20-Nov-12 16:55pm
   
I don't understand your question. Can you explain more, please?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The comma (,) is a list operator. The array operation (operator [] (int index);) has only one argument. The list operator will work in following way: all operations (separated by comma) will been executed but still the last is the operand.
For example you can write int* px = new int [n=calcsize(),n+=8,push(n),42]; will finally be the same like: n = calcsize(); n+=8; push(n); int* px = new int [42];. So at your code all your array operations are using the parameter behind the last comma:
int *b=new int [w+1,3]; is equal to int *b=new int [3];
cin>>f[k,0]; is equal to cin>>f[0];
and so on.
Perhaps you can explan what to achive with your expressions.
Best regards.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 499
1 OriginalGriff 393
2 Maciej Los 385
3 CPallini 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 5,022
2 Maciej Los 3,269
3 Peter Leow 3,164
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100