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

Reg : Pointers

Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

i had gone through one book, i am a bit confused.

Regards,
Satish...
Nov 14 '05 #1
11 1818
"Satish Kumar" <sk********@gmail.com> wrote in message
news:69**************************@posting.google.c om...
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

I had gone through one book, i am a bit confused.


I *do* have a pointer for you:

Google

using the phrase:

Pointers C Tutorial

Cheers,

Anthony Borla
Nov 14 '05 #2
Satish Kumar <sk********@gmail.com> wrote:
Can any one give me indetail about, what are pointers?
Pointers are variables that can hold addresses. Normally, they get
assigned a value that is the address of another object (a normal
variable, a function or another pointer). Once that has happened
you can access what the pointer points to by dereferencing it,
which is done by putting the (unary) '*' operator in front of
the pointer variables name.

So when you have e.g.

int i = 5;
int *ip = &i; /* pointer, pointing to i */

then you can e.g. do

printf( "i is %d\n", *ip );

or

*ip = 7; /* change i indirectly via the pointer */

printf( "i is now %d\n", i )

and this will print out

i is now 7
How are pointers useful in C prgramming?
First of all, they allow you to pass addresses of variables to
functions, and by doing so it is possible to change the content
of the variable pointed to from within the function (remember:
in C variables are passed by value, so a function only receives
the value of an argument variable and can't change the variable
itself).

Second, pointers are indispensable when you need amounts of
memory you can only determine while the program is already
running. Functions like malloc() return you a pointer to a
memory buffer with a size you can tell the function. If the
function succeeds you can use the returned value to access
that memory, e.g.

int *a = malloc( 100 * sizeof *int );
if ( a != NULL ) {
a[ 17 ] = 42;
free( a );
}

But there are hundreds of other uses of pointers and listing
only the small subset which immediately comes to mind would
make this posting much too long. C without pointers would be
a rather useless language.
How do they work?
What do you mean by "work"?
i had gone through one book, i am a bit confused.


We all started that way (more or less). Keep reading and experi-
menting and you will understand soon enough;-) Trying to draw
some boxes representing pointers and variables and arrows de-
picting the relationship between them sometimes helps (especially
if you start playing around with pointers to pointers).

Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #3


Satish Kumar wrote:
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

i had gone through one book, i am a bit confused.

Regards,
Satish...


C-FAQ @ Section 4.

http://www.eskimo.com/~scs/C-faq/top.html

gives a good understanding on Pointers
All the best :)

- Ravi

Nov 14 '05 #4
On 2005-04-01 11:11, Satish Kumar wrote:
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

i had gone through one book, i am a bit confused.

Regards,
Satish...

you can get good material from net
search google with keyword as ' pointers in c '
you can get so many pdf

Nov 14 '05 #5
"Ramasubramanian XR (AS/EAB)" <ra**************************@ericsson.com>
wrote in news:d2**********@newstree.wise.edt.ericsson.se:
On 2005-04-01 11:11, Satish Kumar wrote:
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?

....
you can get good material from net
search google with keyword as ' pointers in c '
you can get so many pdf


Still, one has to choose among what is available.

http://www.eskimo.com/~scs/cclass/notes/sx10b.html

Sinan
--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
Nov 14 '05 #6
Satish Kumar wrote:
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?


I have found that for people to really understand pointers, they need to
understand assembly language and how it works. I wrote a book to teach
assembly language programming, not to make people expert assembly
language programmers, but to instead give them a better idea of how
their computer works and how the languages they use work under the hood.
You can find the book at:

http://www.cafeshops.com/bartlettpublish.8640017

Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
Nov 14 '05 #7
Jonathan Bartlett <jo*****@eskimo.com> scribbled the following:
Satish Kumar wrote:
Can any one give me indetail about,

what are pointers?
How are pointers useful in C prgramming?
How do they work?
I have found that for people to really understand pointers, they need to
understand assembly language and how it works. I wrote a book to teach
assembly language programming, not to make people expert assembly
language programmers, but to instead give them a better idea of how
their computer works and how the languages they use work under the hood.
You can find the book at: http://www.cafeshops.com/bartlettpublish.8640017


I strongly disagree. I have only very limited experience about assembly
language, but I understand the basics about C pointers. In my opinion,
it's enough to know that variables are stored in memory locations, and
pointers store the addresses of those locations.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
Nov 14 '05 #8
Mark L Pappin <ml*@acm.org> writes:
Joona I Palaste <pa*****@cc.helsinki.fi> writes:

[...]
I strongly disagree. I have only very limited experience about
assembly language, but I understand the basics about C pointers. In
my opinion, it's enough to know that variables are stored in memory
locations, and pointers store the addresses of those locations.


I'll have to disagree with both of you here. C pointers _may_ (and in
many common implementations do) store just addresses, but at an
abstract level (where one should be thinking, to avoid UB) each
pointer has both value (which may be invalid in certain circumstances)
and type. Thinking of pointers as addresses leads to such brokenness
as expecting

[snip]

A good point, but I'm going to quibble anyway.

The standard uses the term "address" to mean a pointer value. So if
you follow the terminology of the standard, it's trivially true that
pointers store just addresses. You just need to be aware that they
aren't necessarily "addresses" in the low-level sense used by most
people -- just as C "bytes" aren't necessarily 8 bits.

--
Keith Thompson (The_Other_Keith) 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.
Nov 14 '05 #9
The standard uses the term "address" to mean a pointer value. So if
you follow the terminology of the standard, it's trivially true that
pointers store just addresses. You just need to be aware that they
aren't necessarily "addresses" in the low-level sense used by most
people.

--
Keith Thompson (The_Other_Keith) 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.


Could you please clarify this?

Barry
ba****@highstream.net
Nov 14 '05 #10
"BGreene" <ba****@highstream.net> writes:
Keith Thompson <ks***@mib.org> writes:
The standard uses the term "address" to mean a pointer value. So if
you follow the terminology of the standard, it's trivially true that
pointers store just addresses. You just need to be aware that they
aren't necessarily "addresses" in the low-level sense used by most
people.


Could you please clarify this?


The usual (non-C) sense of the term "address" is a virtual or physical
address recognized by the CPU and/or memory management system.

The C standard uses the term "address" to mean a C pointer value. For
example, the unary "&" (address-of) operator yields an address value.
The C standard defines the semantics, but doesn't say much about the
representation. An "address" in the C sense could be some
higher-level construct than a virtual or physical machine address.
It's an address in the C abstract machine, not necessarily in the
physical machine.

In most implementations, C addresses (pointer values) are machine
addresses, but the C standard is designed to allow a variety of
implementation strategies.

One concrete example is the C implementation on Cray vector machines.
A machine-level address is a 64-bit quantity that points to a 64-bit
machine word, but the C compiler has CHAR_BIT==8, so it needs a
mechanism to point to 8-bit bytes within words. An int* pointer is a
machine address, but a char* or void* pointer has a 3-bit offset
stored in the otherwise unused high-order bits of a word pointer.
This is implemented entirely in code generated by the compiler, not in
hardware. A char* pointer value with a non-zero offset field is a C
address, but it's not a machine address.

--
Keith Thompson (The_Other_Keith) 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.
Nov 14 '05 #11

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"BGreene" <ba****@highstream.net> writes:
Keith Thompson <ks***@mib.org> writes:
The standard uses the term "address" to mean a pointer value. So if
you follow the terminology of the standard, it's trivially true that
pointers store just addresses. You just need to be aware that they
aren't necessarily "addresses" in the low-level sense used by most
people.
Could you please clarify this?


The usual (non-C) sense of the term "address" is a virtual or physical
address recognized by the CPU and/or memory management system.

The C standard uses the term "address" to mean a C pointer value. For
example, the unary "&" (address-of) operator yields an address value.
The C standard defines the semantics, but doesn't say much about the
representation. An "address" in the C sense could be some
higher-level construct than a virtual or physical machine address.
It's an address in the C abstract machine, not necessarily in the
physical machine.

In most implementations, C addresses (pointer values) are machine
addresses, but the C standard is designed to allow a variety of
implementation strategies.

One concrete example is the C implementation on Cray vector machines.
A machine-level address is a 64-bit quantity that points to a 64-bit
machine word, but the C compiler has CHAR_BIT==8, so it needs a
mechanism to point to 8-bit bytes within words. An int* pointer is a
machine address, but a char* or void* pointer has a 3-bit offset
stored in the otherwise unused high-order bits of a word pointer.
This is implemented entirely in code generated by the compiler, not in
hardware. A char* pointer value with a non-zero offset field is a C
address, but it's not a machine address.

--
Keith Thompson (The_Other_Keith) 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.

Thanks for making this clear. The example you gave was well described. It
is similar to the implemetation of all the compilers that ran on HP-PA,
with the exception HP-PA was originally 32 bit, and used the 2 bit (low
order bits) as a "space register." to allow it to address 4G. I don't know
where I read this but I am pretty sure it is true.
Nov 14 '05 #12

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

Similar topics

27
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined...
3
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL,...
9
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar...
12
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
4
by: Josefo | last post by:
Hello, is someone so kind to tell me why I am getting the following errors ? vector_static_function.c:20: error: expected constructor, destructor, or type conversion before '.' token...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
54
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
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: 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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.