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 8708321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:06:20+00:00 2026-06-13T04:06:20+00:00

#include<stdio.h> main() { char c = ‘R’; printf(%c\n,c); c++; printf(%c\n,c); char *ptr =Ramco Systems;

  • 0
#include<stdio.h>
main()
{

        char c = 'R';
        printf("%c\n",c);
        c++;
        printf("%c\n",c);
        char *ptr ="Ramco Systems";
        printf("%c\n",(*ptr));
        (*ptr)++;
        printf("%d\n",(*ptr));

}

The output of the first, second ,3rd printf are ‘R’, ‘S’ & ‘R’ (as expected). However the line “(*ptr)++;” gives runtime error. Can someone explain why ?

  • 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-13T04:06:21+00:00Added an answer on June 13, 2026 at 4:06 am

    The reason is because the memory pointed to be ptr was set at compiletime and is non-modifiable.

    So accessing the first character via *ptr is fine and returns R, but attempting to increment the first character yields a runtime error because you are not allowed to modify strings that you provide at compiletime.

    To expand on Seg Fault’s comment below, a better way to write your code would have been:

    const char *ptr ="Ramco Systems"; //pointer to const char
    (*ptr)++; // yields compiletime error because *ptr is a const char
    

    Notice how in this new code, the declared pointer type is more accurate and as a result the compiler is able to give a compiletime error on the second line (much better than a runtime error).

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

Sidebar

Related Questions

#include <stdio.h> #include <stdlib.h> int main() { char *str=Helloworld; printf(%d,printf(%s,str)); return 0; } output
#include<stdio.h> int main() { char a, b; scanf(%c, &a); scanf(%c, &b); printf(%c %c,a,b); return
#include<stdio.h> int main() { char a='x'; printf(%c %d,a); return 0; } Output: x 134513696
#include<stdio.h> int main() { char str[25] = helloworld; printf(%s %s, &str+2,str+2); return 0; }
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
#include <stdio.h> int main() { char TurHare; while(1) { scanf(%c,TurHare); printf(\nCharacter :%c, TurHare); }
What's wrong with this? #include <stdio.h> void main(){ char *s=some text; printf(%d,is_in(s,'t')); } int
#include <stdio.h> int main() { char temp[1024]; if(getchar() != 'y') { printf(no options\n); return
#include <stdio.h> int main () { char loop='y'; while(loop != 'n') { printf(loop? );
#include<stdio.h> int main(){ char a[6],*p; a[0]='a'; a[1]='b'; a[2]='c'; a[3]='4'; a[4]='e'; a[5]='p'; a[6]='f'; a[7]='e'; printf(%s\n,a);

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.