C data structures and constructs map efficiently to machine language instructions and memory mapping
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World!\n");
return 0;
}
$ gcc hello.c -o hello
$ ./hello
Hello World!
$
Build systems are generally command line programs that read a "configuration" file in a particular format
To use the standard library you often only need to include the headers:
#include <stdio.h>
#include <math.h>
What exactly these steps mean depends on your setup, e.g. how you are handling libraries, your operating system and you IDE.
Many websites like sourceforge.net, github.com or bitbucket.com offer free code hosting under version control
/* A C style
multiline comment
*/
// A C++ style single line comment
int a;
int b = 10;
{
a = 12;
float c = a + b;
}
/* variable c is not available anymore */
int a = 1;
a++; // a is now 2
a += 1; // Equivalent to a++, a is now 3
a /= 2; // What is a now?
#include <stdio.h>
/* Function declarations */
int function1(int value1);
int function2(int value1);
int main(void)
{
int value = function1(5) + function2(10);
printf("%i\n", value);
return 0;
}
/* Function implementations */
int function1(int value1)
{
return value1 + 10;
}
int function2(int value1)
{
return value1 + 20;
}
if (value > 10) {
/* if true */
} else if (value < 10) {
/* < 10 */
} else {
/* value == 10 */
}
for(int i = 0; i < 10; i++) {
printf("%i\n", i);
}
int i = 0;
while (i < 10) {
print("%i\n", i);
i++;
}
int i = 0;
while (i < 10) {
print("%i\n", i++);
}
int a = 10;
int *b;
b = &a; // b is a pointer of type int *
*b = 5; // now a == 5 too