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

pointers to constant characters and constant pointers to characters

Hi Everyone,

I understand the meaning and usage of pointers to constant characters
and constant pointers to characters, however i often get confused with
the syntax of expressing them, can anyone help me out with few examples?

Dec 14 '06 #1
4 2182
sa*****@yahoo.co.in said:
Hi Everyone,

I understand the meaning and usage of pointers to constant characters
and constant pointers to characters, however i often get confused with
the syntax of expressing them, can anyone help me out with few examples?
char *p - p is a pointer to a char
const char *q - q is a pointer to a const char
char const *r - r is a pointer to a const char (don't ask!)
char * const s - s is a const pointer to a char
const char * const t - t is a const pointer to a const char
char const * const u - u is a const pointer to a const char

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Dec 14 '06 #2
sa*****@yahoo.co.in wrote:
Hi Everyone,

I understand the meaning and usage of pointers to constant characters
and constant pointers to characters, however i often get confused with
the syntax of expressing them, can anyone help me out with few examples?
For the simple cases, when no parentheses are involved, you can read
declarations from right to left:

const char *p;
/* 1: p is a pointer to char which is const */

char const *p;
/* 2: p is a pointer to const char (same as 1) */

char *const p;
/* 3: p is a const pointer to char */

char const *const p[4];
/* 4: p is an array of 4 const pointers to const char */

When parentheses are involved it gets a bit more complicated, but it
would probably be better to getting to understand the simple cases
first.

Dec 14 '06 #3
Richard Heathfield wrote
(in article <xJ*********************@bt.com>):
sa*****@yahoo.co.in said:
>Hi Everyone,

I understand the meaning and usage of pointers to constant characters
and constant pointers to characters, however i often get confused with
the syntax of expressing them, can anyone help me out with few examples?

char *p - p is a pointer to a char
const char *q - q is a pointer to a const char
char const *r - r is a pointer to a const char (don't ask!)
char * const s - s is a const pointer to a char
const char * const t - t is a const pointer to a const char
char const * const u - u is a const pointer to a const char
.... and people keep claiming that C is hard to grasp for the
beginner...

lol

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 14 '06 #4
sa*****@yahoo.co.in writes:
I understand the meaning and usage of pointers to constant characters
and constant pointers to characters, however i often get confused with
the syntax of expressing them, can anyone help me out with few examples?
See if you can find a program called "cdecl".

% cdecl
Type `help' or `?' for help
cdecldeclare a as pointer to char
char *a
cdecldeclare b as const pointer to char
char * const b
cdecldeclare c as pointer to const char
const char *c
cdecldeclare d as const pointer to const char
const char * const d

--
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.
Dec 14 '06 #5

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

Similar topics

20
by: dms | last post by:
Hi all, If you have a char pointer (char *var), is there a way I can manipulate specific characters or blocks of characters within the string? eg: char *name; name = "David" then change...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
46
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have...
1
by: ketema | last post by:
Hello, I was wondering if someone could help me with a function I am trying to write. The purpose of the function is to read in text from a file in the following format: FIRSTNAME LASTNAME...
12
by: natkw1 | last post by:
Hi, I'm attempting to understand the use of pointers(at least grasp how pointers work). I've read the FAQ on http://www.eskimo.com/~scs/C-faq/s6.html on pointers and arrays but I'm still a bit...
8
by: Piotrek | last post by:
Hi, Like almost all of beginners I have problem understanding pointers. Please, look at this piece of code, and please explain me why myswap function doesn't work as it's supposed to do, whereas...
27
by: Jess | last post by:
Hello, the following code failed with "segmentation fault". Could someone tell me why it failed please? Thanks! #include<iostream> #include<string> #include<cstring> #include<cstddef> using...
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...
8
by: Rafael Anschau | last post by:
I read that you should assign null (0) to all pointers that you call delete on. Does that mean: *p=0(set the value pointed to to 0). or p=0(set the address held to zero).
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: 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...
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
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...
0
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,...
0
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...
0
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,...

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.