Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
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:

C++
#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
Updated 20-Nov-12 10:18am
v2
Comments
joshrduncan2012 20-Nov-12 16:55pm    
I don't understand your question. Can you explain more, please?
[no name] 20-Nov-12 22:51pm    
what is your problem? i don't understand your question. use Improove link to provide more details

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900