473,321 Members | 1,916 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,321 software developers and data experts.

asking a question about pointer array.

i want to ask from you that how i can dynamically allocate memory to
double dimmensional arry ?please reply.

Apr 24 '07 #1
6 1285

<ra**************@gmail.comwrote in message
news:11**********************@s33g2000prh.googlegr oups.com...
>i want to ask from you that how i can dynamically allocate memory to
double dimmensional arry ?please reply.
It's in the FAQ: http://c-faq.com/aryptr/dynmuldimary.html

--
Jonas
Apr 24 '07 #2
ra**************@gmail.com wrote:
i want to ask from you that how i can dynamically allocate memory to
double dimmensional arry ?please reply.
This is a FAQ. You should always check the FAQ for a newsgroup before
posting question. The one for <news:comp.lang.ccan be found in
several places, including <http://c-faq.com/>. The answer can be found
in question 6.16 "How can I dynamically allocate a multidimensional
array?", which can be found at <http://c-faq.com/aryptr/dynmuldimary.html>.

Apr 24 '07 #3
On Tue, 24 Apr 2007 11:21:31 GMT, "Jonas" wrote:
><rakhshanda.malik@..comwrote in message
>>i want to ask from you that how i can dynamically allocate memory to
double dimmensional arry ?please reply.

It's in the FAQ: http://c-faq.com/aryptr/dynmuldimary.html
See also: http://home.netcom.com/~tjensen/ptr/pointers.htm
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Apr 24 '07 #4
Roland Pibinger wrote, On 24/04/07 19:27:
On Tue, 24 Apr 2007 11:21:31 GMT, "Jonas" wrote:
><rakhshanda.malik@..comwrote in message
>>i want to ask from you that how i can dynamically allocate memory to
double dimmensional arry ?please reply.
It's in the FAQ: http://c-faq.com/aryptr/dynmuldimary.html

See also: http://home.netcom.com/~tjensen/ptr/pointers.htm
This site still needs some work.

In the introduction of the PDF it assumes that PCs use 2 byte int and 4
byte long showing its age. It does note that these sizes need not be the
same on all machines, so not too bad, just dated. Note the HTML version
is more up to date.

It uses %p to print the result of sizeof which is wrong. For C89 it
should use %ul and cast the result to unsigned long.

It at least implies that due to the null pointer not necessarily being
all bits 0 you have to use the NULL macro when, in fact, an integer
constant expression evaluating to zero (most simply 0) is allowed and
the compiler is required to do any magic that is needed.

The author says he thinks of "the name of the array is the address of
the first element in the array" which, in my opinion, is dangerous
because of the difference in type and possible confusion when moving on
to multi-dimensional arrays.

In Chapter 4 it suggests some micro-optimisations in terms of using
pointers and pointer increment to avoid the additions involved in array
indexing. To be fair it says "this may not be true for a modern
optimising compiler" but these days I would say that the "optimisation"
should not even be suggested.

In Chapter 6, when talking about the differences between
char my_string[] = "Ted";
and
char *my_name = "Ted";
It fails to mention one very important difference. Namely that although
the string literal in the second case is not const, you are still not
allowed to modify it (it invokes undefined behaviour, i.e. it could case
the planet to be eaten by an enormous mutant stargoat).

At the end of Chapter 6 it says, "Because of the double de-referencing
required in the pointer version, the name of a 2 dimensional array is
often said to be equivalent to a pointer to a pointer..." While it is
true that this is often said, it is also very misleading because you
cannot pass a 2d array to a function expecting a pointer to a pointer
since they are not the same thing. In the next chapter it makes it a bit
clearer, but I think ending a chapter with something potentially
misleading is bad.

I would also suggest that talking about the old pre-ANSI C is just going
to make it harder for people learning. The chances of a learner coming
across a pre-ANSI compiler are pretty small.

To be fair, I did have to read more carefully than is often the case to
find things to comment on.

I've emailed this to the author of that site. This is meant to be
helpful criticism, not an "avoid that site" message.
--
Flash Gordon
Apr 24 '07 #5
Flash Gordon said:
Roland Pibinger wrote, On 24/04/07 19:27:
<snip>
>>
See also: http://home.netcom.com/~tjensen/ptr/pointers.htm

This site still needs some work.
<snip>
>
It uses %p to print the result of sizeof which is wrong. For C89 it
should use %ul and cast the result to unsigned long.
ITYM %lu

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Apr 24 '07 #6
Richard Heathfield wrote, On 24/04/07 22:37:
Flash Gordon said:
>Roland Pibinger wrote, On 24/04/07 19:27:
<snip>
>>See also: http://home.netcom.com/~tjensen/ptr/pointers.htm
This site still needs some work.
<snip>
>It uses %p to print the result of sizeof which is wrong. For C89 it
should use %ul and cast the result to unsigned long.

ITYM %lu
Thanks for the correction.

Not the only mistake. The site used %d for the result of sizeof which is
not as bad as using %p. Still wrong, just not as bad.
--
Flash Gordon
Apr 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: overbored | last post by:
I can do this: int asdf; int* zxcv = asdf; but not this: int asdf; int** zxcv = asdf;
5
by: pandapower | last post by:
Hi, I know about the equivalence of pointer and arrays.But my doubt comes when its for multidimentional arrays.I have read the C faq but still have some doubts. Suppose I have a declaration as...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
28
by: Wonder | last post by:
Hello, I'm confused by the pointer definition such as int *(p); It seems if the parenthesis close p, it defines only 3 integers. The star is just useless. It can be showed by my program: ...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
14
by: John Gerrard | last post by:
Hi, my name is John and this is my first posting to comp.lang.c. I am learning C. I am a high school student with interest in programming. I have a copy of "The C programming language second...
18
by: mdh | last post by:
>From p112 ( K&R). Given an array declared as static char arr= { { 0,1,........},{0,1,.....}}; let arr be passed as an argument to f. f( int (*arr) ) {....} It is noted that the...
17
by: DiAvOl | last post by:
Hello everyone, merry christmas! I have some questions about the following program: arrtest.c ------------ #include <stdio.h> int main(int agc, char *argv) {
8
by: =?ISO-8859-1?Q?Konrad_M=FChler?= | last post by:
Hi, I've a list of objects. I iterate the list and read the value of each object for many operation like: x = myList.value1 + myList.value2 etc. My question: Is it efficient to always use...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.