473,385 Members | 1,647 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.

Extracting Data from a Triple/Double Pointer pointed to a Multidimensional array

Hi !
Please have a look at the code snippets.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[10] = {"abcdefghi"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
This is working fine.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[3][10] = {"abcdefghi","asdrfe","aserde"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
  9.  
The Second piece of code is failing.

Now the Question is
How to manipulate a Multidimensional Char array using a Double Pointer.
Also
I would like to know the Logic and Usage of multi level pointers
so that i can learn more

It would be of great help to me if you could helpme in resolving this issue

Thanks in Advance .
Sep 25 '07 #1
3 2911
dmjpro
2,476 2GB
Hi !
Please have a look at the code snippets.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[10] = {"abcdefghi"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
  9.  
This is working fine.

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[3][10] = {"abcdefghi","asdrfe","aserde"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
  9.  
The Second piece of code is failing.

Now the Question is
How to manipulate a Multidimensional Char array using a Double Pointer.
Also
I would like to know the Logic and Usage of multi level pointers
so that i can learn more

It would be of great help to me if you could helpme in resolving this issue

Thanks in Advance .
Use Code Tags.
What is ptr, where it defined?
Please let me know :-)

Kind regards,
Dmjpro.
Sep 25 '07 #2
ilikepython
844 Expert 512MB
Hi !
Please have a look at the code snippets.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[10] = {"abcdefghi"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
This is working fine.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3. char arr[3][10] = {"abcdefghi","asdrfe","aserde"};
  4.  
  5. char **Dpp;
  6. Dpp = &ptr;
  7. printf("\n\nThis is test 2\n %s\n ",*Dpp);
  8. }
  9.  
The Second piece of code is failing.

Now the Question is
How to manipulate a Multidimensional Char array using a Double Pointer.
Also
I would like to know the Logic and Usage of multi level pointers
so that i can learn more

It would be of great help to me if you could helpme in resolving this issue

Thanks in Advance .
Basically, I think that the double (pointer to pointer) pointer is the same as 2D array since the name of the array is a pointer to a char pointer and that's exactly what the double pointer is. If you do:
Expand|Select|Wrap|Line Numbers
  1. Dpp = arr;
  2.  
I think you should be able to use Dpp as you use arr.
Sep 25 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
I think you should be able to use Dpp as you use arr.
Nope. Dpp is a pointer to a pointer to a single int. arr is a one-dimensional array of 3 elements where each element is an array of 10 int.
Since the name of the array is the address of element 0, arr is the address of an array of 10 int. The address of an array of 10 int is not the same thing as a pointer to a pointer to a single int.

More info:
First, there are only one-dimensional arrays in C or C++. The number of elements in put between brackets:
Expand|Select|Wrap|Line Numbers
  1. int array[5];
  2.  
That is an array of 5 elements each of which is an int.

Expand|Select|Wrap|Line Numbers
  1. int array[];
  2.  
won't compile. You need to declare the number of elements.

Second, this array:
Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
is still an array of 5 elements. Each element is an array of 10 int.

Expand|Select|Wrap|Line Numbers
  1. int array[5][10][15];
  2.  
is still an array of 5 elements. Each element is an array of 10 elements where each element is an array of 15 int.


Expand|Select|Wrap|Line Numbers
  1. int array[][10];
  2.  
won't compile. You need to declare the number of elements.

Third, the name of an array is the address of element 0
Expand|Select|Wrap|Line Numbers
  1. int array[5];
  2.  
Here array is the address of array[0]. Since array[0] is an int, array is the address of an int. You can assign the name array to an int*.

Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
Here array is the address of array[0]. Since array[0] is an array of 10 int, array is the address of an array of 10 int. You can assign the name array to a pointer to an array of 10 int:
Expand|Select|Wrap|Line Numbers
  1. int array[5][10];
  2.  
  3. int (*ptr)[10] = array;
  4.  
Fourth, when the number of elements is not known at compile time, you create the array dynamically:

Expand|Select|Wrap|Line Numbers
  1. int* array = new int[value][5];
  2. int (*ptr)[10] = new int[value][10];
  3. int (*ptr)[10][15] = new int[value][10][15];
  4.  
In each case value is the number of elements. Any other brackets only describe the elements.

Using an int** for an array of arrays is incorrect and produces wrong answers using pointer arithmetic. The compiler knows this so it won't compile this code:

Expand|Select|Wrap|Line Numbers
  1. int** ptr = new int[value][10];    //ERROR
  2.  
new returns the address of an array of 10 int and that isn't the same as an int**.

Likewise:
Expand|Select|Wrap|Line Numbers
  1. int*** ptr = new int[value][10][15];    //ERROR
  2.  
new returns the address of an array of 10 elements where each element is an array of 15 int and that isn't the same as an int***.
Sep 25 '07 #4

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

Similar topics

2
by: shane | last post by:
Ive searched a fair bit for the answer, but nothing has come up that matches what i want to do. I'm having an issue with passing and assigning pointers to multidimensional arrays. The code: ...
3
by: Heiko Vogel | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hi newsgroup, can anybody tell me, why the following code snippet won't compile: double **ptr; double const ** const c_ptr =...
8
by: Michel Rouzic | last post by:
I had a program that worked perfectly, and that read .wav files. I changed something so the tags of the wave file, instead of being each in a different variable, are all in an array, called tag. i...
14
by: ranjmis | last post by:
Hi all, Below is the code wherein I am initializing double dimentional array inside main with string literals. Now I want to display the strings using a function call to which I just want to...
42
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
31
by: aarklon | last post by:
Hi all, this is a question which i saw in a book typedef struct mall_li_header_ { int refcnt; uchar pool; uchar flag; ushort magic_no; char data;
24
by: Kavya | last post by:
int main (){ int a={{1,2,3},{4,5,6}}; int (*ptr)=a; /* This should be fine and give 3 as output*/ printf("%d\n",(*ptr)); ++ptr;
26
by: Ioannis Vranos | last post by:
Are the following guaranteed to work always as *C90* code? 1. #include <stdio.h> void some_func(int *p, const size_t SIZE) { size_t i;
9
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've an optimization question for you all really quick. I have a stream that I am reading some bytes. At times, the stream can contain a small amount of bytes such as 50...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
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...

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.