C is a general-purpose programming language used for system programming (OS and embedded), libraries, games and cross-platform. This tag should be used with general questions concerning the C language, as defined in the ISO 9899 standard (the latest version, 9899:2018, unless otherwise specified — also tag version-specific requests with c89, c99, c11, etc). C is distinct from C++ and it should not be combined with the C++ tag without a specific reason.
C (pronounced "See", like the letter C) is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the UNIX operating system. Its design provides constructs that map efficiently to typical machine instructions, and therefore it found lasting use in applications that had formerly been coded in assembly language. It is a highly efficient procedural programming language and has an emphasis on functions whereas modern object-oriented programming languages tend to emphasize data.
The C programming language was based on the earlier programming languages B, BCPL, and CPL.
The C language and its optional library are standardized as ISO/IEC 9899, the current version being ISO/IEC 9899:2018 (C17). A draft version N2176 is available for free.
Although C was designed for implementing system software, it is also widely used for developing portable application software.
C is one of the most widely used programming languages of all time and there are very few computer architectures for which a C compiler does not exist. C has greatly influenced many other popular programming languages, most notably C++, which began as an extension to C. Other languages that have been greatly influenced by C are C#, Objective-C and Java.
C is an imperative (procedural) systems implementation language. It was designed to be compiled using a relatively straightforward compiler, to provide low-level access to memory, to provide language constructs that map efficiently to machine instructions, and to require minimal run-time support. C was, therefore, useful for many applications that had formerly been coded in assembly language.
Despite its low-level capabilities, the language was designed to encourage cross-platform programming. A standards-compliant and portably written C program can be compiled for a very wide variety of computer platforms and operating systems with very few changes to its source code. The language has become available on a very wide range of platforms, from embedded microcontrollers to supercomputers.
c Tag usage
When posting questions about C programming, please make sure to include:
- Target system and compiler information. This includes the compiler name, version and settings used to compile.
- In case your question is about compiler errors/warnings, please quote those errors/warnings in the question. Also clarify which line the compiler error refers to.
- If your question is specific to one particular version of the the language, add c90 c99 c11 or c17. Pre-standard, historical questions should be tagged kr-c.
- Unless the question explicitly mentions which version of the C standard that is used, it is assumed that the current version is used. That is, whichever version of ISO 9899 that ISO currently lists as active. Please have this in mind when answering or commenting on questions tagged c.
C and C++ are two distinct and often incompatible languages. Avoid using both tags in the same question unless you have good reasons.
A question should be tagged with c only, if:
- It contains pure C, with no trace of C++, or questions with code that could be either language.
- The code is compiled with a C compiler.
A question should be tagged with c++ only, if:
- It contains code with any C++ features. Even though the code may be "C style".
- The code is compiled with a C++ compiler.
- Specific differences between C and C++.
- Compatibility or porting code between C and C++.
- C++ code that uses C libraries (for example code using
If you encounter a post with both tags, edit/re-tag it if needed according to the above rules. If you can tell the language by reading the posted code, simply edit tags accordingly. Avoid prompting the user "is it C or C++?" in comments unless the question is truly unclear.
One example of an unclear question is when the user explicitly claims that they are programming in C, but posts code or compiler messages for C++. If so, prompt for clarification and close-vote as unclear.
"Either C or C++ is fine" opinions from the OP is a strong indication of a poor or unclear question. Answers may be very different depending on language picked. Prompt for clarification, close as unclear/too broad until the OP has clarified this.
Be careful about re-tagging questions once there are answers posted, particularly if there are already both C and C++ answers posted. In such cases, the tags should be left alone, since changing them would make posted answers invalid.
Answers with C++ code to a C question that has never been tagged c++ should be deleted as off-topic. Please check the question edit history before flagging/deleting such answers, to verify that the question never had the C++ tag.
Books about C
There are many, many books of varying quality about how to use C. See the question Definitive C Book Guide and List.
Note that this question is controversial; it would not be accepted on modern Stack Overflow, but it is a useful historical artifact that is still being maintained.
Frequently Asked Questions (FAQ)
Types and qualifiers
- What is the strict aliasing rule?
- Is char signed or unsigned by default?
- Implicit type promotion rules
- What is the difference between const int*, const int * const, and int const *?
Declaration and initialization
- What is the difference between a definition and a declaration?
- (Why) is using an uninitialized variable undefined behavior?
- How to initialize all members of an array to the same value?
Scope and storage duration
- Can a local variable's memory be accessed outside its scope?
- How do I use extern to share variables between source files?
- What does "static" mean in C?
- Why is unsigned integer overflow defined behavior but signed integer overflow isn't?
- How do I detect unsigned integer overflow?
- What is the behavior of integer division?
- What does an extra 0 in front of an int value mean? (octal constants)
- Why are floating point numbers inaccurate?
- C program to convert Fahrenheit to Celsius (the problem of integer division)
- Is the behaviour of casting a negative double to unsigned int defined in the C standard? Different behaviour on ARM vs. x86
Operators, precedence and order of evaluation
- Why are these constructs using pre and post-increment undefined behavior?
- What is the difference between ++i and i++?
- Is short-circuiting logical operators mandated? And evaluation order?
- With arrays, why is it the case that a == 5[a]?
- How do you set, clear, and toggle a single bit?
- What are bitwise shift (bit-shift) operators and how do they work?
- What does the comma operator , do?
- Why doesn't a+++++b work? ("maximal munch rule")
- Post-increment on a dereferenced pointer? (
- Chaining multiple greater than/less than operators (common FAQ where beginners assume that "interval syntax" like
0 < x < 10is valid C)
- Why does the order of the loops affect performance when iterating over a 2D array?
- Is it faster to count down than it is to count up?
- What is array to pointer decay?
- Is an array name a pointer?
- Why isn't the size of an array parameter the same as within main?
- How dangerous is it to access an array out of bounds?
- Getting a stack overflow exception when declaring a large array
- GCC: Array type has incomplete element type (array with multiple empty  FAQ)
Pointers and null
- How to write C/C++ code correctly when null pointer is not all bits zero
- How to access a local variable from a different function using pointers?
- How to find the 'sizeof' (a pointer pointing to an array)?
- Why does int pointer '++' increment by 4 rather than 1?
- Pointer to pointer clarification
- Crash or "segmentation fault" when data is copied/scanned/read to an uninitialized pointer
- "Pointer from integer/integer from pointer without a cast" issues
- Pointers in C: when to use the ampersand and the asterisk?
- How do function pointers in C work?
- Casting a function pointer to another type
- Why do function pointer definitions work with any number of ampersands '&' or asterisks '*'?
- How should character arrays be used as strings? Missing null terminator FAQ.
- How can I correctly assign a new string value?
- How do I properly compare strings in C?
- What is the difference between char s and char *s?
- Why do I get a segmentation fault when writing to a "char *s" initialized with a string literal, but not "char s"?
- Why are strlcpy and strlcat considered insecure?
- String literals: Where do they go?
- How to split a string into tokens in C? (how to use strtok)
Dynamic memory allocation
- Do I cast the result of malloc?
- Dynamic memory access only works inside function
- Correctly allocating multi-dimensional arrays
Structs and unions
- Why isn't sizeof for a struct equal to the sum of sizeof of each member?
- Partitioning struct into private and public sections? (private encapsulation with opaque type/opaque pointers)
- Typedefs, tagged and untagged structures, and incompatible pointer types
- sizeof() a struct with a zero length array member
The preprocessor and macros
- What is the difference between #include <filename> and #include "filename"?
- Why use apparently meaningless do-while and if-else statements in macros?
- Stringification - how does it work?
- Creating your own header file in C (for FAQ about header/include guards)
- What should main() return in C and C++?
- Where do I find the current C or C++ standard documents?
- What is the difference between C, C99, ANSI C and GNU C?
Undefined, unspecified and implementation-defined behavior
- Undefined, unspecified and implementation-defined behavior
- Definitive List of Common Reasons for Segmentation Faults
- What is a bus error? Is it different from a segmentation fault?
The standard library
- Which functions from the standard library must (should) be avoided?
- How to read / parse input in C? The FAQ
- scanf() leaves the newline character in the buffer
- Removing trailing newline character from fgets() input
- Correct format specifier to print pointer or address?
- Why is “while ( !feof (file) )” always wrong?
- Why is the gets function so dangerous that it should not be used?
- Using fflush(stdin)
- What will happen if '&' is not put in a 'scanf' statement?
- What is the effect of trailing white space in a scanf() format string?
- srand() — why call it only once?
Best practices and style concerns
- Why is the asterisk before the variable name, rather than after the type?
- "static const" vs "#define" vs "enum"
- Is it a good idea to typedef pointers?
- What does a type followed by _t (underscore-t) represent?
- The comp.lang.c FAQ has answers to many frequently asked C questions. For example, see The Clockwise/Spiral Rule for parsing C declarations.
- C Reference provides a reference to C language and standard library functions.
- What Every Computer Scientist Should Know About Floating-Point Arithmetic, by David Goldberg
- cdecl: C gibberish ↔ English, a site that translates C expressions to readable English.
Hello World program in C
Chat about C with other Stack Overflow users
- Repl.it C compiler
- OnlineGDB C compiler
- Tutorialspoint C compiler
- Godbolt - C compiler explorer/disassembler