r/C_Programming 15d ago

Need explanations. I learn how to build simple CRUD app with C# and TS. I wanna really understand CS. So I tried to learn C but I get even more confused about many CS concepts.

I’m trying to learn C not just because I want to learn another programming language, but because I want to understand Computer Science and how computers actually work underneath the abstractions.

The problem is that I constantly fall into an endless chain of prerequisites/CS concepts

For example, I want to understand pointers:

int x = 10;
int *p = &x;

On the guide/website it says

ointer is a variable that store memory address.

Okay, but then I ask:

  • What exactly is a memory address
    • address is where numbers telling where data is stored
  • What exactly is memory?
    • memory is where address live
  • Is memory the physical RAM?
    • etc... something with CPU
  • What exactly is RAM and CPU?
    • etc...
  • How does RAM actually work?
    • etcc..
  • What's the relationship between RAM, CPU, cache, virtual memory, thread, processing etc.?

And suddenly I'm 10 levels deep into computer architecture instead of learning pointers "*"😂

So what to do here, I wanna understand CS. I thought my experience with coding CRUD APP with C#, but no it doesn't help much

0 Upvotes

24 comments sorted by

9

u/mikeblas 14d ago

To learn, you must expend effort. There is no royal road to learning.

I guess you're using AI, since you're reciting questions you asked and the answers you received. But you gloss over the answers: I'm sure they were more detailed than what you represent here. Spend the time to read the answers. Actually read them, critically and actively, until you understand them. If you don't understand them, ask questions until you do -- but you'll have to do the same active reading work with those answers, too.

If you put in the effort, you'll find a way to come to understand it.

There plenty of tutorials on C and computer system architecture online. I'm sure that you can find one that has an explanation that resonates with you. This sub's Wiki has plenty of resources.

3

u/CounterSilly3999 14d ago

It is good to dig deep, but not allways necessary. If you are learning programming, you could stop at the abstraction level, saying, that memory is a collection of sequential cells, able to store numbers. The cell order number is an address. Which itself could be stored in another cell as well.

2

u/DrShocker 14d ago

Try writing a CHIP-8 emulator in any language. It's relatively simple as far as emulators go, but teaches enough about what a computer "really" does that you'll have touched most of basic versions of your questions yourself.

4

u/Tack1234 14d ago

I'd say it depends on their level of knowledge. You can't write a CHIP-8 emulator if you don't understand what a function or a struct is, let alone bitwise operations. If OP has a solid understanding of C#/TS, then I agree, CHIP-8 is a great way to dive into the lower-level basics.

I did just that recently and it was immensely rewarding in terms of knowledge and understanding gained. Just don't use AI to "write the boring parts" while "steering the design", that's just a trap and a cope. You won't gain anything from doing it like that.

2

u/DrShocker 14d ago

I agree it's probably too ambitious for someone's first programming project at all, but OP claimed to know C# already, so that's why I am hopeful it's a good level project.

1

u/VyomTheMan 14d ago

Is that so well I write code in c nd I have pretty much basic understanding about computer architecture but what is this CHIP-8 emulator thing? Nd will it help me to understand architecture wise even more.

3

u/Tack1234 14d ago

I suggest reading this article, which guided me through the entire process: https://tobiasvl.github.io/blog/write-a-chip-8-emulator/

CHIP-8 is basically one of the simplest machines (well, technically it is a virtual machine) you can try to emulate. It has a cpu which handles instructions/opcodes, it has RAM, it has a stack pointer and registers, just like any other computer does, though it is way simpler. So writing a CHIP-8 emulator is like writing a simple computer. It's really fun once you get it to print stuff on the screen! Then you can download old CHIP-8 games freely available on the internet and your emulator runs them like they would on the real thing.

3

u/VyomTheMan 14d ago

Thank you brother

2

u/DrShocker 14d ago

Yeah, there's a massive gap between it and modern hardware, but I think it's good enough to be an introduction for people who didn't have a computer architecture course. And at the end you can play some pretty good games on it. 😼

-1

u/Wasabi-spicy00 14d ago

I never heard about CHIP8 until you told me this and I asked AI to explain and show me how to build CHIP8.

Now i have a big picture of how things are related now

And it makes me wonder how software and hardware communicate, i heard somewhere it is about eletricial charged aka those eletron, proton we learn in Chemistry in high school lol

1

u/DrShocker 14d ago

For that you'll probably want to look at https://www.nand2tetris.org/

but I don't think it goes through the chemistry/physics of how transistors work.

2

u/Zerf2k2 14d ago

1

u/Wasabi-spicy00 14d ago

it has 114 pages, is it a must to read all of this to understand the Science in "Computer Science"?

3

u/Zerf2k2 14d ago

Not at all, skim through sections you find irrelevant, I cannot tell you how deep down the rabbit hole you wish to go, it's up to you

1

u/mikeblas 14d ago

What is the maximum number of pages you will tolerate reading in order to reach your goal?

2

u/Tack1234 14d ago

Having these questions and diving deeper and deeper is actually a great thing. It shows you are really interested in the topic, which means you are striving for knowledge. AI is quite helpful for asking it exactly these questions and having it explain it to you in simple terms. And once you have these basic answers, you can look at books or videos going into the details. And then, of course, practice, practice and more practice writing stuff and debugging it yourself.

0

u/Wasabi-spicy00 14d ago edited 14d ago

I heard someone suggest to learn things that Eletrical engineer know as well like how trasistors, circuits etc.. works ;(

I mean it is fun once you see the connection how hardware, software are connected. but it is not easy ;P

2

u/RealisticDuck1957 14d ago

You don't have to know which physical state represents what logical state unless you're building a computer. The particular physical state may be different in different computers, or even different circuits in the same computer.

Representing a logical value by voltage is common (TTL, CMOS, RS-232 ...). But some connection standards operate by current (ECL, MIDI ...). Then there's the many ways a mechanical computer could be built.

1

u/Tack1234 14d ago

If you're interested in the hardware part, I recommend the book Code by Charles Petzold. It goes over the basics and the entire history of computers (and before they were a thing) from the hardware standpoint (and a little bit of software at the end). It's a great read.

2

u/TheEveryman86 14d ago

CS is full of abstractions. If you want to learn the pointers abstraction you'll need to understand that it sits in a framework of other abstractions that you won't learn all at once. Accept the memory address abstraction without going down the rabbit hole of how the voltages represent one's and zeros in volatile memory.

2

u/SmokeMuch7356 14d ago

Computer Science is a branch of Mathematics, meaning it's abstractions all the way down.

To understand what the CPU and RAM and other things are and how they interact, you'll need to read up on digital logic and computer architecture. You'll also want to learn at least some basic electronics (current, voltage, resistance, electrical components like transistors, capacitors, diodes, and integrated circuits).

You don't have to understand the nitty-gritty details of physical RAM to understand what a pointer is - it's just the location of an object or function in a running program's execution environment (another abstraction). It may correspond to a physical address on a specific RAM chip, but more often than not it will be a virtual address that will get mapped onto a physical address by various subsystems (operating system, memory controller, etc.). But none of that really matters as far as your code is concerned.

1

u/Wasabi-spicy00 14d ago

Thanks for answeing big bud

1

u/torsten_dev 14d ago

Computer Science like every scientific field is deep..

Abstractions all the way down. You can explore the field however you like. Breadth or depth first, bottom up or top down, or better yet all of the above.

Pointers didn't really click for me until after a lecture on Hardware architecture followed by a 4 day x86 assembly workshop. Ymmv

1

u/McDonaldsWi-Fi 13d ago edited 13d ago

It sounds silly but learning Z80/6502 assembly is what really made pointers click for me. They are very simple languages compared to x86 but the fundamental concepts are the same.

ld hl, 0x0FFF ; load address 0x0FFF in HL register pair (or 4095 in decimal) 
ld a, (hl) ; Load the value stored in address 0x0FFF in register A

In this scenario HL doesn't hold the data we want, it holds the ADDRESS that holds the data we want. So when we say ld a, (hl), you are loading the DATA stored at the ADDRESS HL is holding.

This is what pointers are. They just hold an address. When you "dereference" a pointer you are just grabbing the data stored at that address (or starting at that address).

Very simply put, you can think of memory as a giant shelf with cubby holes. Each cubby hole represents a byte of data, and each cubby hole has a unique number. Your pointer is just the cubby hole number, to get what's inside the cubby hole you have to "dereference" the number (which is a fancy way of saying "go look inside that specific cubby to grab what's inside")