Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:09:52+00:00 2026-06-09T08:09:52+00:00

typedef char* c; const c ptr1 = pointer; ++ptr1; /// error const char* ptr2

  • 0
typedef char* c;
const c ptr1 = "pointer";
++ptr1; /// error
const char* ptr2 = "pointer";
++ptr2; /// runs fine

Now ptr1 should be of type const char* and thus a non-const pointer, then why is it being treated as a constant pointer ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:09:53+00:00Added an answer on June 9, 2026 at 8:09 am

    They are not the same.

    The first designates a const-pointer-to-char, the second is a pointer-to-const-char.

    Try reading right to left:

    const char *p;  // p is a pointer to char which is const
    char const *p;  // p is a pointer to const char (same as previous)
    char * const p; // p is a const pointer to char
    char const * const p; // p is a const pointer to const char
    

    By using the typedef typedef char* c you pack the meaning “pointer to char” into a single alias c:

    const c p; // p is a const [c] --> p is a const [pointer to char]
    

    Additional explanations:

    Typedefs are not in-place-expanded like macros are, i.e.

    const c p;
    

    really becomes

    const [char*] p;
    

    it does not become

    const char* p; // Nope.
    

    Don’t expand it like macros in your mind, with the typedefs, you’ve bound char and * together and formed an atom.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure: typedef struct stock { const char* key1p2; // stock code
I'm having problems with const char array being stored to a struct, then when
The situation: typedef unsigned int u32; typedef unsigned char u8; const u8 *x; ...
Firstly, sample codes: Case 1: typedef char* CHARS; typedef CHARS const CPTR; // constant
I have this code typedef struct { const char* fooString; const bool fooBool; }fooStruct;
I'm looking at LPSTR which is defined as typedef char* PSTR, *LPSTR; The documentation
this is my struct typedef struct { char mmsi[10]; char name[20]; double latitude; double
I structures like the following typedef struct { char *ptr; size_t used; size_t size;
Do you prefer to see something like t_byte* (with typedef unsigned char t_byte )
I have a structure typedef struct store { char name[11]; int age; } store;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.