473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pointers

I am realy confussed bout pointers.. Can you guys please tell me what
is the difference or is there any kinds of pointers ?

char** a;
char *a;
*char a;

etc if there is any that i don't know or i am wrong.

Thanks

Regards,
Billy

Nov 14 '05 #1
33 2335
On 8 Mar 2005 06:39:45 -0800, in comp.lang.c , "ByteSurfer "
<by********@gma il.com> wrote:
I am realy confussed bout pointers.. char** a;
pointer to a pointer to a char
char *a;
pointer to a char
*char a;


syntax errror.
If you need to understand this better, usenet is a REALLY bad place to do
distance learning. Sit down calmly with your C textbook, and work carefully
through the chapter on pointers.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #2
<11************ *********@f14g2 000cwb.googlegr oups.com>
ByteSurfer <by********@gma il.com> wrote:
char** a;
a is a pointer to a pointer to a char.
char *a;
a is a pointer to a char.
*char a;


Syntax error.

--
Christopher Benson-Manica
ataru(at)cybers pace.org
Nov 14 '05 #3
*char a; IS NOT VALID AT ALL.

Look at this example:

char chr = 'a'; /* Just another char */
char* pchr = &chr; /* A pointer to the char above */
char** ppchr = &pchr; /* A pointer to the pointer to the char */
char*** pppchr = &ppchr; /* A pointer to a pointer to a pointer to a
char */

This can go on for a while (your code will probably crash after added
tons of *, but there doesn't have to be a limit. It's all compiler and
machine specific.)

Now you can use this pointers. Adding a * in front of a pointer (not
when declaring it, but ever after) will give you the stuff inside a
pointer. You could therfor do something like this:

printf("The char chr is: %c\n", chr);
printf("The char pointed to by pchr is: %c\n", *pchr);
printf("The char pointed to by ppchr is: %c\n", **ppchr);
printf("The char pointed to by pppchr is: %c\n", ***pppchr);

Now I know this may sound a bit confusing, but when you understand
pointers it wil be much clearer. I can recomend you to read this
chapter in a online book on c:
http://publications.gbdirect.co.uk/c_book/chapter5/
It will basicly try to teach you everything about pointers.

One last thing. Usaly you never need more than a pointer and in some
cases a pointer to a pointer. It's actualy pretty weird to see a
pointer to a pointer to a pointer.

--
bjrnove

Nov 14 '05 #4
some times is am kinda confused.
they like to code

char* a;
char *a;

is that both are of the same ??

and some more is it :

*const char a;
-> a pointer of a constant address to a character

const char* a; or const char *a;
-> a constant value of a char.

then how bout *const char* a;

will the spaces char* and char * the same ??

Nov 14 '05 #5
> some times is am kinda confused.
they like to code

char* a;
char *a;

is that both are of the same ?? Yes.

and some more is it :

*const char a;
-> a pointer of a constant address to a character No. Its an error. You want:
char const * a;

const char* a; or const char *a;
-> a constant value of a char. It's a pointer to a char. NOT a char.
char a; is a char.

then how bout *const char* a; Not valid.
char* const* a; is valid thow.

will the spaces char* and char * the same ??

Yes.
char * a;
is the same as
char* a;

Spaces doesn't mather as long as you have one space it's a space. The
rest is ignored by the compiler.

Nov 14 '05 #6
ByteSurfer <by********@gma il.com> wrote:
some times is am kinda confused.
they like to code char* a;
char *a; is that both are of the same ??
Yes, it doesn't matter if you have white space before or after the '*'.
There's also the third and fourth possibility:

char * a;
char*a;

That shows it doesn't matter at all where and how much white space
you put before ot after the asterisk.

Some people prefer 'char*' to 'char *' because they feel that it
makes it more obvious that the variable to be defined is a pointer,
while others don't like it because they feel that it makes it easier
to overlook that in

char* a, b;

'b' isn't a pointer but a simple char variable despite the '*' after
the 'char'.
and some more is it : *const char a;
-> a pointer of a constant address to a character
No, that's a syntax error. You can't have a '*' at the start when
defining a variable.
const char* a; or const char *a;
-> a constant value of a char.
No, that's a pointer to an array of chars with the attached promise
that you won't change the contents of what the pointer points to.
This is quite useful when you use pointers that point to literal
strings, i.e.

const char *my_hello = "Hello, boys and girls!";

because the compiler may be able to gently remind you you're doing
something stupid when you don't keep your promise, or when you use
this for function arguments to indicate that the function is not
going to change the elements of the array it receives. An example is

char *strcpy( char *dest, const char *src );

This makes it immediately clear that strcpy() will only change the
destination string, but will leave the source string alone. And
again it doesn't matter if you have white space before or after
the '*' or before and after the asterisk or none at all.
then how bout *const char* a;
will the spaces char* and char * the same ??


That's also a syntax error.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Nov 14 '05 #7
Je***********@p hysik.fu-berlin.de writes:
while others don't like it because they feel that it makes it easier
to overlook that in

char* a, b;

'b' isn't a pointer but a simple char variable despite the '*' after
the 'char'.


This is a flaw in the C standard, in my opinion. Logically the "*" is
a modifier of the type. To associate it with the identifier rather
than the type is to confuse its function.
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
ra*********@son yericsson.com, 919-472-1124
Nov 14 '05 #8
In article <xx************ *@usrts005.corp users.net>,
ra*********@son yericsson.com says...
Je***********@p hysik.fu-berlin.de writes:
while others don't like it because they feel that it makes it easier
to overlook that in

char* a, b;

'b' isn't a pointer but a simple char variable despite the '*' after
the 'char'.


This is a flaw in the C standard, in my opinion. Logically the "*" is
a modifier of the type. To associate it with the identifier rather
than the type is to confuse its function.


No, it's a flaw in the way people use it.

If they did it correctly, I.e.

char *a, b;

or even better

char *a;
char b;

then it would be obvious. Multiple variables on one line isn't
necessarily lazy, but it does lead to a lot of strange bugs,
particularly for those not already fluent in the language.
--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #9
Randy Yates <ra*********@so nyericsson.com> writes:
Je***********@p hysik.fu-berlin.de writes:
while others don't like it because they feel that it makes it easier
to overlook that in

char* a, b;

'b' isn't a pointer but a simple char variable despite the '*' after
the 'char'.


This is a flaw in the C standard, in my opinion. Logically the "*" is
a modifier of the type. To associate it with the identifier rather
than the type is to confuse its function.


The principle is that declaration mimics use (more or less). Specifically,

char *a;

means that "*a" is of type char (from which you can infer that a is of
type pointer-to-char). Similarly,

char arr[10];

means that arr[whatever] is of type char (from which you can infer
that arr is of type array-of-char).

Yes, it can be confusing, and if you could only apply a single "*" or
"[...]" to a type name it would be silly, but you need to understand
the principle (or have a copy of the cdecl program) to be able to
decipher things like

void (*signal(int sig, void (*func)(int)))( int);

It's often helpful to avoid putting too many things on one line,
either by declaring only one variable per line or by using
intermediate typedefs.

--
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.
Nov 14 '05 #10

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

Similar topics

27
3390
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 as ff: typedef struct { float *data ; int count ;
3
3441
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, or one-past the end of the object as long as it isn't dereferenced. I use "object" in the standard 'C' sense. Is there some special dispensation given to comparing two pointers
9
5056
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 = getter(file); What type should I give to `getter' so that the compiler does not issue
12
4076
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 VB.NET get compiled into the same code, then I don't understand why VB.NET can't support pointers Thanks for any info Lance
14
2821
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 contents, use the "Bookmarks" tab in Adobe Acrobat. Comments, corrections, praise, nits, etc., are still welcome!
92
5062
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, but I just don't know. I don't like them because I don't trust them. I use new and delete on pure pointers instead. Do you use smart pointers?
4
3503
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 vector_static_function.c:21: error: expected constructor, destructor, or type conversion before '.' token
25
13019
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 *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
54
11965
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 the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously concerned that there is a shift to raw pointers. We are not developing system software but rather...
2
2974
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 standard dynamic address book program. Adding, and listing work just fine. However, deleting, editing and viewing relies on member function retAddress. This function returns an array of pointers that are pointing to created objects. In action, all it...
0
8385
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8303
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
8821
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
8723
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...
1
8502
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7316
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
6162
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
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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

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.