Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

C

< >

C is an open source programming language created in 1972 by Dennis Ritchie.

#2on PLDB 52Years Old 2mRepos
Leet Sheet · REPL · Spec · Wikipedia · Subreddit · Docs

C (, as in the letter c) is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems. C was originally developed by Dennis Ritchie between 1969 and 1973 at Bell Labs, and used to re-implement the Unix operating system. Read more on Wikipedia...


Example from Compiler Explorer:
// Type your code here, or load an example. int square(int num) { return num * num; }
Example from Riju:
#include <stdio.h> int main() { printf("Hello, world!\n"); return 0; }
Example from hello-world:
#include <stdio.h> main() { printf("Hello World\n"); }
Example from Linguist:
#ifndef HELLO_H #define HELLO_H void hello(); #endif
Example from Wikipedia:
#include <stdio.h> int main(void) { printf("hello, world\n"); }
C gets credit for the // comments, starting in 1972, but that's not really accurate. BCPL -- which begat B which begat C -- had // comments but they were not included in C until C99. C++ (which isn't included in their top 30 languages) brought back // comments from BCPL sometime between 1979 and 1985 (the first public release of cfront). Many C compilers included // comments as an extension prior to C99 but those were inspired by C++
auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while

Language features

Feature Supported Example Token
Standard Library #include
Scientific Notation
Conditionals
Constants
While Loops
Case Sensitivity
Assignment =
Switch Statements switch(expression) { case true : break; default : // break; }
Print() Debugging printf
MultiLine Comments /* A comment */ /* */
Line Comments // A comment //
Increment and decrement operators
Zero-based numbering
Variadic Functions double average(int count, ...) { // }
Operators 1 + 1;
Manual Memory Management #include #include int main(void) { int *poin = malloc(4); free(poin); }
Macros // https://learn.microsoft.com/en-us/cpp/preprocessor/macros-c-cpp?redirectedfrom=MSDN&view=msvc-170 // https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html #define min(X, Y) ((X) < (Y) ? (X) : (Y)) x = min(a, b); → x = ((a) < (b) ? (a) : (b)); y = min(1, 2); → y = ((1) < (2) ? (1) : (2)); z = min(a + 28, *p); → z = ((a + 28) < (*p) ? (a + 28) : (*p));
Integers int pldb = 80766866;
File Imports // If a header file is included within <>, the preprocessor will search a predetermined directory path to locate the header file. If the header file is enclosed in "", the preprocessor will look for the header file in the same directory as the source file. #include #include "stdio.h"
Type Casting double da = 3.3; double db = 3.3; double dc = 3.4; int result = (int)da + (int)db + (int)dc; //result == 9
Directives #include #define height 10 #ifdef #endif #if #else #ifndef #undef #pragma
Gotos // C/C++ program to check if a number is // even or not using goto statement #include using namespace std; // function to check even or not void checkEvenOrNot(int num) { if (num % 2 == 0) goto even; // jump to even else goto odd; // jump to odd even: cout << num << " is evenn"; return; // return if even odd: cout << num << " is oddn"; } // Driver program to test above function int main() { int num = 26; checkEvenOrNot(num); return 0; }
Structs struct account { int account_number; char *first_name; char *last_name; float balance; };
Comments // A comment
Explicit Standard Library #include // Define a public function double foo(int count) { double sum = 0.0; // Sum all the values bar(1) to bar(count) for (int i = 1; i <= count; i++) sum += bar((double) i); return sum; } // Symbol Table: // Symbol name|Type|Scope // bar|function, double|extern // x|double|function parameter // foo|function, double|global // count|int|function parameter // sum|double|block local // i|int|for-loop statement
Symbol Tables // Declare an external function extern double bar(double x);
Bitwise Operators int i = 4; /* bit pattern equivalent is binary 100 */ int j = i << 2; /* makes it binary 10000, which multiplies the original number by 4 i.e. 16 */
Assert Statements #include int i, a[10]; for (i = 0; i < 10; ++i) { assert(0 <= i && i < 10); a[i] = 10-i; } for (i = 0; i < 10; ++i) { assert(0 <= i && i < 10); assert(0 <= a[i] && a[i] < 10); a[a[i]] = a[i]; }
Strings "hello world"
Pointers int *ptr;
Ternary operators #include int main(void) { printf("%d", 1 ? 1 : 0); }
Characters char character = 'P';
Booleans
Enums enum Gender { Male, Female, };
Fixed Point Numbers X
Case Insensitive Identifiers X
Exceptions X
Classes X
Access Modifiers X
Semantic Indentation X
Operator Overloading X
Templates X
Multiple Inheritance X
Namespaces X
Garbage Collection X
Constructors X
Regular Expression Syntax Sugar X
Variable Substitution Syntax X

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v154.3.0