To compete with @HahaYes C++ tutorial, I take the side of C, as defined in The C programming language, second edition by Brain Kerninghan and Dennsi Ritchie.
This section is very meta about C, and is not Strictly required.
Every C program has two parts:
Functions
Variables
Or, to be even more meta:
Code
Data
Let's dissect hello.c, line for line:
#include <stdio.h>
This may look like elvis elvish, but it is very simple.
The # char indicates a preprocesser directive.
The directive in question Primeinclude, includes other code in your program.
The prefix std means standard, and io means input/ouput
int main()
This is a function, or a snippet of code.
Every function has the form return_type name(args)
In this one, we have a return type of int, named main that takes no arguments
{
In C, a curly brace ({/}) seperates blocks of code. In this case, all you need to know is that all code between { and } is part of main
printf("Hello world");
This is another function, like main.
It is named printf. In non-programmer speak, it means print with formatting. The formatting part is in Chapter two. It takes one -or two- arguments, the string to print, and the format string.
All lines that don't start with a # or are a function end with ;. No exceptions. Ever.
In this case, we are asking it to print Hello world with no formmatting.
return 0;
This is a special statment, return. It returns a piece of Data, like a gift. For main, the return value is normally used to tell if the program failed, or worked.
0: It worked
1: General error
2+: Random error
And, last but not least:
}
This tells your computer that your are done with main and want to move on.
Chapter 1, part 3
Your challenge
You need to make a program that prints out three things:
Your favorite Browser (Firefox)
The operating system you don't like the most (Windows 10)
Customer:
Morning
Waitress:
Morning
Customer:
What have you got?
Waitress:
Well, there's egg and bacon
Egg sausage and bacon
Egg and C
Egg, bacon and C
Egg, bacon, sausage and C
C, bacon, sausage and C
C, egg, C, C, bacon and C
C, sausage, C, C, C, bacon, C tomato and C
C, C, C, egg and C
C, C, C, C, C, C, baked beans, C, C, C and C
(Choir: C! C! C! C! Lovely C! Lovely C!)
Or Lobster Thermidor aux crevettes with a Mornay sauce
Served in a Provençale manner with shallots and aubergines
Garnished with truffle pâté, brandy and a fried egg on top and C
Wife:
Have you got anything without C?
Waitress:
Well, the C, eggs, sausage and C
That's not got much C in it
Wife:
I don't want any C!
Customer:
Why can't she have eggs, bacon, C and sausage?
Wife:
That's got C in it!
Customer:
Hasn't got much C in it as C, eggs, sausage and C has it?
(Choir: C! C! C!...)
Wife:
Could you do me eggs, bacon, C and sausage without the C, then?
Waitress:
Iiiiiiiiiiiich!!
Wife:
What do you mean 'Iiiiiiiiiich'? I don't like C!
(Choir: Lovely C! Wonderful C!)
Waitress (to choir):
Shut up!
(Choir: Lovely C! Wonderful C!)
Waitress:
Shut Up! Bloody Vikings!
You can't have egg, bacon, C and sausage without the C
Wife:
I don't like C!
Customer:
Shush dear, don't have a fuss. I'll have your C. I love it
I'm having C, C, C, C, C, C, C, baked beans
C, C, C, and C!
(Choir: C! C! C! C! Lovely C! Wonderful C!)
Waitress:
Shut Up!! Baked beans are off
Customer:
Well, could I have her C instead of the baked beans then?
Waitress:
You mean C, C, C, C, C, C, C, C, C, C, C
C and C?
Choir (intervening):
C! C! C! C!
Lovely C! Wonderful C!
C c-c-c-c-c-C C c-c-c-c-c-c C
Lovely C! Lovely C! Lovely C! Lovely C!
C C C C!
Hello, World! 🖖
To compete with @HahaYes C++ tutorial, I take the side of C, as defined in The C programming language, second edition by Brain Kerninghan and Dennsi Ritchie.
Edit: Chapter two is out
Now:
Let the games begin!
Chapter 1, part 1:
Hello World
The only real way to learn a language is to start programming in it.
So, we will do
Hello world
.Code
Please make a new C repl, and enter this code into it.
(No Copy-Paste)
Run
If you are in repl, press C-ret, or 'Run'
If you are on a *NIX system use this:
gcc hello.c -Wall -Werror -o main.o && chmod +x main.o && ./main.o
If you are on Windows, download 50G of IDE and C++/Python/NET compilers (VS) and make a new project and hope your computer won't crash.
Output
You should see this appear in your terminal:
Chapter 1, part 2
Meta time
This section is very
meta
about C, and is not Strictly required.Every C program has two parts:
Or, to be even more meta:
Let's dissect hello.c, line for line:
#include <stdio.h>
This may look like
elviselvish, but it is very simple.The
#
char indicates apreprocesser
directive.The directive in question
Primeinclude
, includes other code in your program.The prefix
std
meansstandard
, andio
means input/ouputint main()
This is a
function
, or a snippet of code.Every function has the form
return_type name(args)
In this one, we have a return type of
int
, namedmain
that takes no arguments{
In C, a curly brace (
{/}
) seperates blocks of code.In this case, all you need to know is that all code between
{
and}
is part of mainprintf("Hello world");
This is another function, like main.
It is named
printf
. In non-programmer speak, it means print with formatting. The formatting part is in Chapter two. It takes one -or two- arguments, the string to print,and the format string.All lines that don't start with a
#
or are a function end with;
. No exceptions. Ever.In this case, we are asking it to print
Hello world
with no formmatting.return 0;
This is a special statment,
return
. It returns a piece of Data, like a gift.For
main
, the return value is normally used to tell if the program failed, or worked.And, last but not least:
}
This tells your computer that your are done with
main
and want to move on.Chapter 1, part 3
Your challenge
You need to make a program that prints out three things:
Please give them to me in the comments
Example output:
Part One: The Segfault menace
Part Two: The data wars
Part Three: Revenge of the if
Part Four: A new loop
Part Five: The Empire points back
Part Six: Return of the function
@HahaYes