50 Fun Facts About C Programming
Learn something new, then test yourself with the quiz.
Know these facts? Prove it.
Take the 50-question quizWhich creator of the C programming language died in October 2011, only days after Apple co-founder Steve Jobs?
Dennis Ritchie was found dead at his New Jersey home on October 12, 2011, aged 70. Steve Jobs had died seven days earlier, on October 5.
The default and most widely used interpreter for which language, created by Guido van Rossum, is written in C?
Python's standard interpreter is named CPython for exactly that reason. A rival implementation, PyPy, is written in a restricted dialect of the language itself.
Which operating system kernel, begun by a Finnish university student in 1991, is written mostly in C?
Linux was started by Linus Torvalds at the University of Helsinki, who announced it online as "just a hobby, won't be big and professional". Most of its kernel code is still C.
Which Epic Games engine, first built for a 1998 first-person shooter, is written in C++?
Unreal Engine takes its name from Unreal, the 1998 shooter it was made for. Epic founder Tim Sweeney began developing it in 1995.
The "sharp" in the name of the C# programming language was borrowed from which field?
Musical notation uses a sharp sign to raise a note by a semitone, so C# hints at a step up from C. The name is typed with a number sign because most keyboards lack the true sharp symbol.
The 1978 book The C Programming Language made which phrase the traditional output of a first program?
"Hello, world" was printed by the book's opening example, and programming tutorials have copied it ever since. Co-author Brian Kernighan had already used the phrase in a 1974 in-house memo.
C was developed as the successor to which earlier language, written by Ken Thompson around 1969?
B was typeless, treating every value as a machine word, a weakness that pushed its authors to build an expanded version with types. That expanded version became C.
The "++" in the name C++ is a programmer's joke based on which operator of the C language?
Increment is what ++ does in C, adding one to a variable, so the name suggests C taken one step further. The language was briefly called C84 before the new name stuck.
Which operating system was rewritten from assembly language into C in 1973, helping it spread to other computers?
Unix had first been written in assembly for the PDP-7, which tied it to that one machine. Once nearly all of it was in C, it could be moved to new hardware far more easily.
Which technology company introduced the C# language in 2000, with a design team led by Anders Hejlsberg?
Microsoft first showed C# to developers in July 2000. It considered keeping the working name COOL, but dropped the idea for trademark reasons.
A C program starts running in which function, whose return value becomes the program's exit status?
The main function can take no parameters or two, which carry the command-line arguments. Since the C99 standard, reaching its closing brace without a return statement counts as reporting success.
Which C standard library function writes text to the screen, filling placeholders such as %s with values?
The name printf stands for "print formatted". The function also hands back the number of characters it wrote, or a negative value if the output failed.
Which header file must a C program include before calling input and output functions such as puts and getchar?
The stdio.h header also defines the FILE type, which holds everything needed to control a stream. The same header therefore covers reading and writing files on disk.
In C, C++ and C#, which punctuation mark ends a statement, so that a missing one stops the program compiling?
Semicolon endings mean the compiler ignores where a line stops, so one statement can run across several lines. Groups of statements are then bundled into blocks with curly braces.
Arrays in C, like those in most languages descended from it, number their first element with which index?
0 is the first index because a subscript in C is really an offset from the start of the array, and the opening element sits at no offset at all.
In C, a single equals sign assigns a value; which operator tests whether two values are equal?
The == operator is easy to mistype as a lone equals sign, which assigns instead of comparing. In many cases that slip compiles without any error message.
Which C operator, written between two integers, gives the remainder left after dividing the first by the second?
The % operator yields only the leftover, so 17 % 5 is 2. If the right-hand value is zero, the C standard leaves the behaviour undefined.
In a C switch statement, which keyword stops execution from falling through into the next case?
A break exits the switch at once; without it, C simply carries on into the code of the following case. That fall-through is legal, so a forgotten one compiles cleanly.
Which C loop tests its condition only after each pass, so its body always runs at least once?
A do-while loop puts its test at the bottom, after the body has already run. The plain while loop checks before the first pass, so it may never run at all.
Which C keyword, written in place of a return type, declares that a function gives back no value?
The void keyword was missing from the earliest versions of C, where a function with no stated result simply defaulted to returning an int.
Which C standard library function reserves a requested number of bytes and leaves their contents uninitialised?
A call to malloc hands back a null pointer when the request cannot be met, so careful code tests the result before using it. The block stays reserved until the program explicitly gives it up.
Which C allocation function takes an element count and an element size, and sets every byte it returns to zero?
Because calloc clears the whole block, an array it returns can be read straight away. It also does the count-times-size multiplication itself instead of leaving it to the caller.
Which C function changes the size of an existing allocation, moving the data to a new address if it must?
A realloc call keeps the old contents up to the smaller of the two sizes. If memory runs out it returns a null pointer and leaves the original block intact.
In C, memory requested at run time comes from which region, as opposed to the stack used for local variables?
The heap is an area set aside for this purpose, and a block taken from it stays reserved until the program hands it back. Automatic variables instead come and go as functions are called and return.
What is the name for the bug in which a C program keeps allocating storage but never releases it?
A memory leak can go unnoticed in a short-lived tool, because modern operating systems reclaim everything when a program exits. In software that runs for months, the loss keeps growing.
Which adjective describes a C pointer that still holds the address of memory that has already been released?
A dangling pointer looks valid but refers to memory the program no longer owns. If the system has since handed that memory to something else, writing through it silently corrupts unrelated data.
Which error is raised when a C program tries to read or write memory it is not allowed to access?
A segmentation fault is raised by hardware memory protection, which alerts the operating system that a program has strayed outside its own space. The usual response is to end the program on the spot.
The gets function was removed from C in the 2011 standard because it made which security flaw unavoidable?
A buffer overflow was always possible because gets is never told how big its destination is. A long enough line of input simply keeps writing past the end.
Which C operator, usually written with a type name in parentheses, reports how many bytes that type occupies?
The sizeof operator looks like a function call but is built into the language itself. Its result has the unsigned type size_t, the same type the allocation functions expect.
Which symbol is used in C both to declare a pointer and to reach the value it points to?
The asterisk does double duty: in a declaration it marks a variable as a pointer, and in an expression it dereferences one. C also uses the same symbol for multiplication.
Which symbol, placed before a variable name in C, produces the address where that variable is stored?
An ampersand before a name yields a pointer to it, the form that functions need when they must change a caller's variable. Between two values, the same symbol means bitwise AND.
Which C library function counts the characters in a string, stopping just before the terminating null character?
A strlen call has to walk the whole string to find the terminator, so its running time grows with the text. C strings carry no stored length that it could simply look up.
The C standard defines the size of which data type as exactly one byte, whatever the machine?
A char is one byte by definition, but the standard does not promise that a byte is eight bits. The real width on a given machine is published in the constant CHAR_BIT.
Which C keyword makes a local variable keep its value from one call of a function to the next?
A static local is initialised only once and then lives for the entire run of the program. Used at file level, the same keyword instead hides a name from other source files.
Which C type stores all of its members in overlapping storage, so only one can hold a value at a time?
A union is only as big as its largest member, because the others share those same bytes. A struct, by contrast, lays its members out one after another.
Which C preprocessor directive creates a macro, telling the compiler to swap a name for replacement text?
A #define works by plain text substitution before the code is compiled, so the compiler proper never sees the macro's name. Macros can also take arguments, so they look like function calls.
In C, the caret symbol does not raise a number to a power; which bitwise operation does it perform?
XOR sets a result bit only where the two inputs differ, so in C the expression 5 ^ 2 is 7 rather than 25. Real powers need the library function pow.
Which C keyword warns the compiler that a variable can change outside the program's control, such as a hardware port?
Marking a variable volatile forces every read and write of it to really happen, in order, instead of being optimised away. Device drivers rely on it for memory-mapped hardware.
Because both operands are integers, what does the C expression 7 / 2 evaluate to?
3 is the result because integer division in C throws away the fractional part, truncating towards zero. Making either operand a floating-point number gives 3.5 instead.
Edsger Dijkstra's famous 1968 letter argued that which statement, still part of C, should be considered harmful?
The goto statement jumps straight to a labelled line, which Dijkstra argued makes programs harder to analyse and verify. C kept the statement regardless.
C was created at which research laboratory, also credited with the transistor, the laser and information theory?
Bell Labs was the research arm of the telephone giant AT&T, and its Murray Hill site in New Jersey produced both the transistor and C. Its staff later created C++ and AWK as well.
Which Danish computer scientist created C++, beginning the work in 1979 as an extension of C?
Bjarne Stroustrup wanted a language as efficient and flexible as C that also offered high-level features for organising programs. Its first international standard arrived in 1998.
Before it acquired its final name, the language now called C++ was known by which descriptive title?
"C with Classes" began in 1979 and bolted classes, derived classes, strong typing and inlining onto plain C. The team also referred to it for a while as "new C".
In C++, members of a class declared without any access specifier receive which access level by default?
Members are private unless stated otherwise in a class, but public by default in a struct. That default is the chief difference between the two keywords in C++.
Which special C++ member function, named with a tilde before the class name, runs when an object's lifetime ends?
A destructor is where a C++ object gives back whatever it acquired during its lifetime, such as memory or an open file. For a local variable the call comes automatically at the end of its scope.
Which C++ feature lets one piece of code work with many data types, as in the container vector<int>?
Templates let a function or class be written once and then instantiated for whatever types a program needs. The standard library's containers are all class templates.
Which object does a C++ program typically combine with the << operator to print text to the screen?
The name cout means "character output", and the object is declared in the header iostream. It writes to the same standard output stream that C's own printing functions use.
Unlike C and C++, the C# language reclaims unused objects automatically through which runtime mechanism?
Garbage collection is the only route in C#: managed memory cannot be released by hand at all. The runtime decides when an object is no longer reachable and reclaims it.
Anders Hejlsberg, lead architect of C#, went on to work on which language that compiles to JavaScript?
TypeScript reached the public in October 2012 after two years of internal development. Hejlsberg had earlier created the Turbo Pascal compiler and Delphi.
Which language's creator, James Gosling, dismissed the newly launched C# as an imitation of his own work?
Java's creator called C# "sort of Java with reliability, productivity and security deleted". Its lead designer replied that C# was no clone and sat much closer to C++.
Think you know C Programming?
Put these facts to the test with the interactive quiz.
Take the 50-question quizTeaching C Programming?
Make a custom quiz — handy for classrooms and study groups.
Make a quiz on anything