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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:29:15+00:00 2026-06-07T11:29:15+00:00

I’m doing Learn C the hard way for self-study coming from knowing a bit

  • 0

I’m doing “Learn C the hard way” for self-study coming from knowing a bit of Python. I have read several tutorials, but I can’t get my head around how pointers and assignment works. I understand that if you dereference the pointer, you can directly give it a value as in:

int *anint = 42;

But what about specifically referencing the memory location of an already-created variable?
Specifically, I tried:

char *pointer_to_strlit;
char *strlit = "some stuff";
pointer_to_strlit = &strlit;

Why does the following cause a segfault after I do this:

printf("I print strlit: %s\nI print it again by pointing to it: %s\nI print where the pointer is pointing: %p\n", strlit, *pointer_to_strlit, pointer_to_strlit);

The types in C seem really hard tell how they will behave and how to use pointers to reference the specific types. Is there a clear guide that specifically outlines the syntax for pointing to each different datatype (char, *char, *char[], int, struct, void, null, functions, etc.)? Even a list of steps that would help me understand the rule set would be useful.

  • 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-07T11:29:16+00:00Added an answer on June 7, 2026 at 11:29 am

    Hang in there! Pointers will make sense after more practice. But when in doubt, try to reason about what each value means. Using pen and paper to try to draw each byte in memory really helps.

    char *pointer_to_strlit; – here you declare a pointer to a character. As you probably already know, a string in C is represented by a pointer to the first character of that string. The string is expected to be null-terminated. This means that eventually there should be an ASCII 0 character indicating that the string has ended.

    char *strlit = "some stuff"; – your program’s memory will contain characters for this string (11 characters to be exact — 10 for the text you see, and 1 for the null terminator). Here you declare another pointer, this time pointing to first character “s” from that string.

    pointer_to_strlit = &strlit; – this sets the value of pointer_to_strlit to the address of the pointer strlit. This is probably not what you want here.

    If things get confusing, try to think of each pointer as a plain old number — that’s essentially what a pointer is, a huge number representing an address in memory. Let’s look at the above again:

    char *pointer_to_strlit; – Here the value of pointer_to_strlit is undefined since you didn’t set it yet.

    char *strlit = "some stuff"; – Let’s say the address of the first “s” is 1234500. The value of strlit will be that number, 1234500.

    pointer_to_strlit = &strlit; – But what is the address of strlit itself? It’s some other value, let’s say 1234600. The value of pointer_to_strlit will now be 1234600.

    Try to print pointer_to_strlit as a %s now, and your program will crash — at the address 1234600 is not the first character of a string, but another number — one of the bytes of the huge number, the pointer. The code will try to traverse what it thinks is a string to look for the null-terminator, eventually crashing when it reaches inaccessible memory.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

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.