473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Pointer and Array

hallo all
This is first time I viset the website,, Actually i'm a IT student .I have a project
abuot class , array and pointer.My question is how I can move between the cells by pointer (new operator)?!.
I hope someone help me .
that all and thanx alot.
Aileen.
Apr 7 '12 #1
3 1575
Thnx for answer me ,but a class should be able to check if the user refers to an element that
is out of range is boundaries of the specified array,so the columns of array is
different sizes.
could you check this plz:
int *p;
p = new int[3][4];
cout<<*p;
Apr 7 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
Not quite correct.

Your array p has 3 elements where each element is an array of 4 int. The new operator returns the address of element 0 of p, which is p[0]. Since the name of an array is the address of element 0, p[0] is the address of an array of 4 int:

Expand|Select|Wrap|Line Numbers
  1. int (*p)[4];
  2.  p = new int[3][4];
  3.  cout<< p[0][0];    //element 0 of p[0]
Also remember that all you have is the address of these arrays. There's no way to know how many elements. You will need to keep track of ths using a variable which you provide to all functions that you provide the array address:

Expand|Select|Wrap|Line Numbers
  1. const int numrows = 3;
  2.  const int numcols = 4;
  3.  int (*p)[numcols];
  4.  
  5.  p = new int[numrows][numcols];
  6.  MyFunction(p, numrows, numcols);
  7. etc...
Apr 7 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bryan Parkoff | last post by:
I want to allocate pointer array into memory so pointer array contains ten pointers. It would be 4 bytes per pointer to be total 40 bytes. Looks like below for example. unsigned char* A = new...
5
by: Brett | last post by:
Sorry for the rookie question.... If I have a pointer array (for example): char *colors = { "blue", "green" }; and I want to add yellow to this array later in my code....how would I do
2
by: Min-su KIM | last post by:
HI~ I need to access the pointer array via DLL. Original C code is char * buf; for (int i = 0; i < 63; i++) { buf = new char ; } API_CALL(buf);
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
1
by: nozone | last post by:
Hi. I am new to the C language. I need to store the commands from input to a pointer array without any ""declaration. How to create an pointer array by memory allocation? I tried to use the following...
1
by: MyCGal | last post by:
Hi, I have this code I wrote to copy any length lines into array of pointers. The problem is after storing the individual lines into the char pointer array, the dispaly() chops off some lines...
5
Nosnibor
by: Nosnibor | last post by:
Need some direction as how to implement a pointer array which will mimic a 2D array. Any suggestions? This is where I am. Do not work, but i am working on it. Please send suggestions. I think my...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
13
by: pereges | last post by:
Hi, can some one please tell me why this program is not able to function properly. I have a array a and i am trying to create a pointer array b which points to elements less than 40 in a. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.