r/C_Programming • u/Zealousideal-Pen-456 • Jun 26 '26
Do you think beginners should learn memory concepts alongside scanf()?
A lot of introductory material focuses on syntax first:
scanf("%d", &num);
but skips the explanation that scanf() is writing directly into memory.
I've found understanding memory addresses early makes pointers much less intimidating later.
1
Upvotes
•
u/AutoModerator Jun 26 '26
Looks like you're asking about learning C.
Our wiki includes several useful resources, including a page of curated learning resources. Why not try some of those?
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
6
u/Drach88 Jun 26 '26
The purpose of scanf in beginner curricula is not to teach people how to get input. It's to give them a simple way of getting input that they can copy, so the lesson can explain other concepts and syntax that uses that input. A lesson on assigning variables and simple arithmetic operators needs input, and scanf satisfies that role.
The fact of the matter is that relying on scanf for user input is simply a bad practice outside of learning contexts and very narrow usages, that should soon get replaced in their curricula by safer functions like fgets. Scanf is great for parsing data of a guaranteed known shape. It's mediocre-to-dangerous for use in accepting user input, which can basically be anything.
What you're touching on is a matter of pedagogy. Explaining how memory works won't stick if people don't have the context to understand how it's being used or what the purpose of learning it is. If you jump directly to concepts that are removed from someone's mental model, you risk losing them over something they don't understand the connection to.
Everything that keeps any state whatsoever is written to memory in one way or another. It doesn't need to be explicitly stated.
Once they are at the point of understanding syntax well enough to be conversant, then that's a great time to start an overview of explaining memory as a continuous address space, stack vs heap vs code/data regions etc, and even that is mostly a useful abstraction until they get to virtual memory addresses and OS memory abstraction.
11
u/necr0111 Jun 26 '26
First, they need to understand what memory is, how it works, bits, bytes, binary, and hexadecimal. It sounds silly, but most people might understand the code, but they don't really understand what it's doing. Most people skip those parts. Skipping those parts will cause problems in the future, like understanding unsigned char for example.
4
u/v_maria Jun 26 '26
pointer and address syntax is at the heart of c. its much more important than scanf
3
u/flatfinger Jun 26 '26
IMHO, instead of having students use scanf or fgets, teachers should give students a "just copy/paste this and don't worry for now how it works" function that is actually designed to have good semantics for console input. Unfortunately, all "standard" functions have at least one rubbish aspect.
2
u/nderflow Jun 26 '26
Is this just rage bait? Nobody at all should use scanf. If you don't know why, just search this subreddit.
2
u/mikeblas Jun 26 '26
Then maybe you should stick to the material that doesn't. Seems pretty simple.
1
u/Limp-Confidence5612 Jun 26 '26
I've been learning C for almost a year soon. Haven't even used scanf once... I feel like yes, you should know what the functions you are using do under the hood. You should know how to write it yourself. If i need user input, I have my own hand-written functions for that. If I would ever want to use scanf, it would just be a cursory read of the man pages, and I would be up to speed.
1
u/grimvian Jun 26 '26
It's very natural for beginners trying to input data and print it. I think a good pedagogical teacher can speed up the understanding of memory and think it's all bytes.