SITERAW

What is the difference between "stdio" and "stdlib"?

Author Message
Altcoiner # Posted yesterday
Altcoiner

Hello everyone ^^

In the tutorial on C, in beginner\'s toolbox, the author explicitly states that there are two required C libraries that you must always include: #include <stdio> and #include <stdlib>

I was wondering why 2? Is there a difference between <stdio> and <stdlib>?

Also, could a code potentially work without those two libraries?

Thanks!

Ads
Phoenix # Posted yesterday
Phoenix

I'd rather you add .h to your libraries.

#include <stdio.h>
#include <stdlib.h>

As for your question, STDIO is for input and output, so essentially it's printf and scanf. You can read the documentation for more info.

As for STDLIB it's more complicated. I don't know why J. added it as compulsory, as you can absolutely run a beginner C program without it. It deals mostly with memory allocation: malloc, free, exit, etc, which is all stuff you only need starting part III of the course.

Phantom # Posted two hours ago
Phantom

He literally answers the question in the C tutorial. Right in the first chapter FFS.

If you really want to know everything — stdio stands for "standard input/output" and lets you display text (among other things), while stdlib deals more with memory management and handy math functions.

Clara # Posted two hours ago
Clara

Be nice to noobs yall

To answer the last question I would guess that a program that does pure math or something could do without either. If you don't write in the console you don't need stdio.h. Likewise stdlib.h is much less common than you think.

Phoenix # Posted one hour ago
Phoenix

Doing "pure math or something" without handling memory...? Wow. That's hardcore.

Clara # Posted one hour ago
Clara

LOL fingers faster than my brain this morning. I meant to say a purely calculatory program could run without stdio.h.

Valter # Posted 7 minutes ago
Valter

Hate to do the "ackshually" meme.

int main() {
int a = 5, b = 10;
int sum = a + b;
return 0;
}
And:
int main() {
__asm__("mov $0, %eax");
return 0;
}
Don't see why either couldn't work in a standard environment.

Post a reply

Please be kind and courteous in your replies. Don't roast others for no reason.