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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:55:37+00:00 2026-05-17T06:55:37+00:00

#include<stdio.h> int main() { char *p=mystring; return 0; } String literal mystring, where will

  • 0
#include<stdio.h>
int main()
{
   char *p="mystring";
   return 0;
}

String literal “mystring”, where will be stored( in which segment) ?
I am assuming that address of “mystring” is stored in ‘p’,’p’ will be in data segment and “mystring” will be stored in code segment. If my assumption is write can i say ‘p’ is a far pointer ? Please correct me if i am wrong.

  • 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-05-17T06:55:38+00:00Added an answer on May 17, 2026 at 6:55 am

    C itself has no concept of segments (nor far pointers), this will be a feature of the underlying implementation or architecture (which you haven’t specified). Segmented architectures and near/far/tiny pointers are ancient things from the 8086 days – most code nowadays (with the possible exception of embedded stuff) gives you a flat memory model where you don’t have to worry about that.

    All the standard states is that the actual characters of the string will be characters that you are not allowed to modify.

    For what it’s worth (which isn’t much). my implementation stores the string itself in memory marked read-only (this may or may not be a code segment, you can easily have other segments marked read-only) and p (the address of the first of those characters) is placed on the stack at runtime.

    If you run your compiler to produce the assembler output:

    gcc -S qq.c
    

    you’ll see something like (in qq.s in my case):

            .file   "qq.c"
            .def    ___main;        .scl    2;      .type   32;     .endef
            .section .rdata,"dr"
    LC0:
            .ascii "mystring\0"
            .text
    .globl _main
            .def    _main;  .scl    2;      .type   32;     .endef
    _main:
            pushl   %ebp
            movl    %esp, %ebp
            subl    $8, %esp
            andl    $-16, %esp
            movl    $0, %eax
            addl    $15, %eax
            addl    $15, %eax
            shrl    $4, %eax
            sall    $4, %eax
            movl    %eax, -8(%ebp)
            movl    -8(%ebp), %eax
            call    __alloca
            call    ___main
            movl    $LC0, -4(%ebp)
            movl    $0, %eax
            leave
            ret
    

    You can see from that, it’s in its own section rdata (read-only data), not in the text section.

    A possible disadvantage of placing it into text would be that things like DEP (data execute protection) would be much harder.

    You want both code and read-only data to be read-only, but you also want code to be executable – you don’t generally want read-only data to be executable.

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

Sidebar

Related Questions

Code : #include stdio.h #include string.h int main() { char *p = abc; printf(p
/* strchr example */ #include <stdio.h> #include <string.h> int main () { char str[]
#include stdio.h #include conio.h #include <iostream> using namespace std; int main (void) { char
Consider the following code: #include <stdio.h> #include <ctype.h> char* Mstrupr(char* szCad); int main() {
Why do we at all use integers in C? #include<stdio.h> int main() { char
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
So I've got some C code: #include <stdio.h> #include <string.h> /* putting one of

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.