473,804 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A beginner's problem

I got from a book a 2D array(a[i][j] is resolved by compiler as
a[i][j]=*(&a[0][0]+total_columns* i+j); // ->1
[Stephen Holzners Assembly Language with C]
And I know when I use pointer to array I should refer
a[i][j]=*(*(a+i)+j); ->2
Is this also resolved by the compiler to (->1) (Awkward question I
know)
And my main question is why we use *(a+i) here

In the pointer to array notation
a[i][j]=*(a[i]+j);
& this again resolves to
a[i][j]=*(*(a+i)+j);
which is same as (2)
Then whats the need of both array of pointers and pointer to array
Is this makes compilers work easy

Dec 27 '05 #1
7 1469
"smartbegin ner" <rr******@gmail .com> writes:
I got from a book a 2D array(a[i][j] is resolved by compiler as
a[i][j]=*(&a[0][0]+total_columns* i+j); // ->1
[Stephen Holzners Assembly Language with C]
And I know when I use pointer to array I should refer
a[i][j]=*(*(a+i)+j); ->2
Is this also resolved by the compiler to (->1) (Awkward question I
know)
And my main question is why we use *(a+i) here

In the pointer to array notation
a[i][j]=*(a[i]+j);
& this again resolves to
a[i][j]=*(*(a+i)+j);
which is same as (2)
Then whats the need of both array of pointers and pointer to array
Is this makes compilers work easy


Have you read section 6 of the comp.lang.c FAQ (<http://c-faq.com/>)?
If not, please do so, then feel free to come back with any questions
you still have.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 27 '05 #2
I'm a student,i want to ask how to learn the c language.
Thank you very much!

Dec 27 '05 #3
tz*****@gmail.c om said:
I'm a student,i want to ask how to learn the c language.
Thank you very much!


If you have prior programming experience in some other language, I recommend
that you start by buying a copy of:

The C Programming Language, 2nd Ed. Kernighan & Ritchie. Prentice Hall,
1988. ISBN 0-13-110362-8 (paperback), or 0-13-110370-9 (hardback).

If you have no previous experience, I instead suggest one of these two
books:

C Programming: A Modern Approach, K.N.King, W.W.Norton & Company, 1996.
ISBN 0-393-96945-2

C: How to Program, 2nd Ed. Deitel, H.M. & Deitel, P.J. Prentice Hall, 1994.
ISBN: 0-13-226119-7
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 27 '05 #4

<tz*****@gmail. com> wrote
I'm a student,i want to ask how to learn the c language.
Thank you very much!

Create an ASCII file with the contents

#include <stdio.h>

int main(void)
{
printf("Hello world\n");
return 0;
}

Now get a C compiler. Fiddle with the compiler until the program compiles
and links.

Now modify the program to print out "Goodbye cruel world".
Then modify the program agian to do something else.
Continue modifying the program until you can make it do whatever you want.
Dec 27 '05 #5
smartbeginner wrote:

I got from a book a 2D array(a[i][j] is resolved by compiler as
a[i][j]=*(&a[0][0]+total_columns* i+j); // ->1
[Stephen Holzners Assembly Language with C]
And I know when I use pointer to array I should refer
a[i][j]=*(*(a+i)+j); ->2
Is this also resolved by the compiler to (->1) (Awkward question I
know)
And my main question is why we use *(a+i) here

In the pointer to array notation
a[i][j]=*(a[i]+j);
& this again resolves to
a[i][j]=*(*(a+i)+j);
which is same as (2)
Then whats the need of both array of pointers and pointer to array
Is this makes compilers work easy


Unless some C standard or other has changed things, rely on the
following:

x[5] is the same as *(x+5)

x[5][4] is the same as *(*(x+5)+4)

x[5][4][6] is the same as *(*(*(x+5)+4)+6 )

and so on...
The multiplications are taken care of because adding an
integer to a pointer causes the integer to be scaled by
the size of what is pointed to.

My whole life is pretty much based on this... ;-)

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Dec 27 '05 #6
Malcolm wrote:
<tz*****@gmail. com> wrote
I'm a student,i want to ask how to learn the c language.
Thank you very much!


Create an ASCII file with the contents

#include <stdio.h>

int main(void)
{
printf("Hello world\n");
return 0;
}

Now get a C compiler. Fiddle with the compiler until the program compiles
and links.

Now modify the program to print out "Goodbye cruel world".
Then modify the program agian to do something else.
Continue modifying the program until you can make it do whatever you want.

That's pretty good advice. I still do a lot of that. Of course now I
call it Software Engineering and Code Re-use. :-)

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Dec 27 '05 #7
On 26 Dec 2005 20:34:26 -0800, "smartbegin ner" <rr******@gmail .com>
wrote:
I got from a book a 2D array(a[i][j] is resolved by compiler as
a[i][j]=*(&a[0][0]+total_columns* i+j); // ->1
[Stephen Holzners Assembly Language with C]
And I know when I use pointer to array I should refer
a[i][j]=*(*(a+i)+j); ->2
You may think you know this but you had it wrong in your previous
message thread.
Is this also resolved by the compiler to (->1) (Awkward question I
know)
And my main question is why we use *(a+i) here

In the pointer to array notation
a[i][j]=*(a[i]+j);
& this again resolves to
a[i][j]=*(*(a+i)+j);
which is same as (2)
Then whats the need of both array of pointers and pointer to array
Is this makes compilers work easy


What is the need of integer and float? The answer to both questions
is they do different things and part of your design process is to
choose the object type that works best for your needs and code
accordingly.

There are four key points:

If is a is an array and p is a pointer, then a[i] and p[i] both
designate the i-th object in the collection (assuming it exists).

In most expressions, a term with type array evaluates to the
address of the first element of the array with type pointer to
element.

The [ ] operator associates left to right. This means that
a[i][j] is treated as (a[i])[j], a[i][j][k] is treated as
((a[i])[j])[k], etc.

The language standard states that a[i] is equivalent to *(a+i).
Note that a+i is an expression in pointer arithmetic, not integer
arithmetic, as explained in my response to your previous message
thread. This makes intuitive sense since a+i is the address of the
i-th object and *(a+i) dereferences this address to yield the object
itself, just as described in the first paragraph above.

Chaining these rules together in the correct sequence and applying
them recursively where needed, keeping track of the type of each
expression, will show that a[i][j] always evaluates to *(*(a+i)+j).
This works if a is an array, a pointer to an array, or a pointer to
pointer.
<<Remove the del for email>>
Dec 28 '05 #8

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

Similar topics

3
2992
by: jvax | last post by:
Hi all, I hope I'm posting in the right NG... I have a data text file I want to read from a c++ program. the data file goes like this: 90 # number of balls 33 42 13
5
3083
by: Richard B. Kreckel | last post by:
Hi! I was recently asked what book to recommend for a beginner in C++. I am convinced that you needn't study C in depth before learning C++ (though it helps), but cannot find any beginner's book which isn't aimed at people coming from C/Pascal/Java/Delpi/whatever... However, there seem to be plenty such books for all those other languages. Is there really no literature for people trying to learn programming by starting with C++? ...
18
2929
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner? Are there better languages than c for a beginner? For instance visual basic or i should just keep the confidence of improving?
20
2299
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
10
2431
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type of free IDE. So I discovered that I needed to download a virtual server, so I downloaded OmniSecure and followed the set up instructions as far as I could figure them out. So here is where I'm stuck. 1) While trying to set up and configure...
4
2818
by: Bails | last post by:
Hi Im an absolute beginner in programming and am using VB.Net Express. To start my larning I decided to do a "Real World" app instead of "hello world" and am creating a Poker Countdown clock. I pretty much have most things under control and have set it up as follows: Form 1 Contains a DataGridView where users enter in information includeing the length of each round, small blind & big blind (its for
5
2754
by: macca | last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP beginner - Reccommendations please? Thanks Paul
10
4473
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
1
1464
by: H. Fraser | last post by:
I've downloaded all of the code and video dealing with the RSS Reader but when i try to run it, it throws an exception, saying 404 page not found. And, As a total beginner, i've no idea where the problem is in the code or else I would have sorted it out my self. If anyone have a fix for it please tell me. Thank you in advance. Hugh Fraser
22
18154
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10599
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10346
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9173
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3832
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.