473,408 Members | 2,477 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,408 software developers and data experts.

regarding pointers to characters

Hi Everyone,

I have the following two cases,

typedef char* cptr;
const cptr ch;
//here ch is a pointer to a character and the pointer is a constant
here...

where as

#define CPTR char*
const CPTR ch;
//here ch is a pointer to character and the character is a constant
here...

What is the reason behind this???

Dec 17 '06 #1
3 1077
sa*****@yahoo.co.in writes:
Hi Everyone,

I have the following two cases,

typedef char* cptr;
const cptr ch;
//here ch is a pointer to a character and the pointer is a constant
here...

where as

#define CPTR char*
const CPTR ch;
//here ch is a pointer to character and the character is a constant
here...

What is the reason behind this???
Is this a homework problem?

--
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 17 '06 #2
>
Is this a homework problem?
No, not at all, homeworks were a long time ago, i know that macro
(string replacement) is before compilation, but i'm not very clear with
typedefs, i thought answer to this might help me understand it better...

Dec 17 '06 #3
sa*****@yahoo.co.in writes:
I have the following two cases,

typedef char* cptr;
const cptr ch;
//here ch is a pointer to a character and the pointer is a constant
here...

where as

#define CPTR char*
const CPTR ch;
//here ch is a pointer to character and the character is a constant
here...

What is the reason behind this???
A typedef creates an alias for a type. Macro expansion works on text
(tokens, actually) with no regard for what those tokens might mean in
context.

In your second example, "CPTR" expands to "char*", so the declaration
is:

const char* ch;

Consider also the following example:

#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}

--
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 17 '06 #4

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

Similar topics

4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
7
by: Squignibbler | last post by:
Hi all, I have a question regarding the C++ programming language regarding the nature of the relationship between pointers and arrays. If the statement MyArray is functionally identical to...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
0
by: Paul Hsieh | last post by:
"Paul D. Boyle" <boyle@laue.chem.ncsu.edu> wrote: > There was a recent thread in this group which talked about the > shortcomings of fgets(). I decided to try my hand at writing a > replacement...
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...
22
by: lifemom | last post by:
hi , im new to this group. one of my friend attended an interview and she got a qtn of writing a pgm to reverse a string. they asked to do with help of pointers.can anyone write the pgm and...
4
by: sam_cit | last post by:
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...
13
by: arnuld | last post by:
at the very beginning of the chapter, i see some statements i am unable to understand. i know the "Pointer" takes the address of a variable, useful if, in case, we want to manipulate that variable...
6
by: =?utf-8?B?4piG4piG4piG4piG4piGIFPDvCBLZWl0aCBDaGFr | last post by:
Ok. Let's say Im writing a game and I have a class table for my character's stats. (Don't worry about classes yet ,you'll run into them soon enough). Say this table includes all his stats, age,...
3
by: JOhn | last post by:
can someone please post some complicated question on pointers?? moreover while reading pointers I found out that there is a lot of difference between an arracy of intergers and an array of...
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: 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: 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
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
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...
0
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,...
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
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...
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.