rtfd/in/public/code/c/index.rst

92 lines
947 B
ReStructuredText
Raw Normal View History

2018-12-11 20:38:01 +00:00
C
=
2018-12-11 21:07:14 +00:00
Imports
-------
2018-12-11 20:38:01 +00:00
.. code:: c
#include <stdio.h>
2018-12-11 21:07:14 +00:00
Comments
--------
.. code:: c
// single line comment
/* multi line comment */
Main
----
.. code:: c
2018-12-11 21:24:36 +00:00
void main() {
2018-12-11 20:38:01 +00:00
system("pause");
}
2018-12-11 20:43:19 +00:00
2018-12-11 20:56:47 +00:00
Declarations
------------
2018-12-11 20:43:19 +00:00
.. code:: c
2018-12-11 21:24:36 +00:00
// unsigned, sizeof()
char c = '1';
short s = 2;
int i = 4;
long l = 8;
float f = (float)4;
double d = (double)8;
long double ld = (long double)16;
2018-12-11 21:07:14 +00:00
Output
------
.. code:: c
printf("int: %d\n", entry1);
printf("float: %.2f\n", f);
2018-12-11 20:56:47 +00:00
Input
-----
.. code:: c
2018-12-11 20:53:43 +00:00
scanf("%d%s%d", &entry1, &operator, &entry2);
Conditions
----------
.. code:: c
if (condition) {
expression1;
} else {
expression2;
}
.. code:: c
switch (operator) {
case '+':
expression1;
break;
default:
printf("Nope!\n");
}
2018-12-11 20:56:47 +00:00
Loops
-----
2018-12-11 21:07:14 +00:00
.. code:: c
for (declarations;conditions;increments) {
expression1;
}
2018-12-11 20:56:47 +00:00
.. code:: c
while (condition) {
expression1;
}