Hub Nexus

All publications

C programming

An open textbook from Wikibooks, a chapter a page, in reading order.

40 pagesUpdated

Get an email when a page is added. Not when one changes.

Version: 1CC BY-SA 4.0
[C]( is the most commonly used programming language for writing [operating systems]( The first operating system written in C was [Unix]( Later operating systems like [GNU/Linux]( were all written in C. Not only is C the language of operating systems, but it is also the precursor and inspiration for
Version: 1CC BY-SA 4.0
The Algorithmic Language ([Algol 58]( was derived from Fortran in 1958 and evolved into [Algol 60]( in 1960. The [Combined Programming Language (CPL)]( was then created out of Algol 60 in 1963. In 1967, it evolved into [Basic CPL]( (BCPL), which was the basis for [B]( which was created in 1971, and
Version: 1CC BY-SA 4.0
It's also assumed you have some experience interacting with your operating system through a terminal window using its **command line interface.** If you aren't sure what this means, consider seeking out a tutorial for your chosen platform that can get you comfortable with getting around your compute
Version: 1CC BY-SA 4.0
Therefore, you can use Dev C++ for C development. However, Dev C++ is not the compiler. It is designed to use the [MinGW]( or [Cygwin]( versions of [GCC]( - both of which can be obtained as part of the Dev C++ package, although they are completely different projects. Dev C++ simply provides an edito
Version: 1CC BY-SA 4.0
Though your compiler understands it, you can only guess at what the code, sprinkled with some familiar English words, might do. One of your first jobs as a new programmer will be to learn the many "words" and symbols of the C programming language, the language your compiler understands. Once you lea
Version: 1CC BY-SA 4.0
Before learning C syntax and programming constructs, it is important to learn the meaning of a few key terms that are central in understanding C, as well as the basic structure of a C program. So what is in a block? Generally, a block consists of executable statements. ## Statements A statement can
Version: 1CC BY-SA 4.0
Having covered the basic concepts of C programming, we can now briefly discuss the process of compilation. Like any programming language, C by itself is completely incomprehensible to a [microprocessor]( Its purpose is to provide an intuitive way for humans to provide instructions that can be easily
Version: 1CC BY-SA 4.0
Machines process things. We feed stuff into a machine and get different stuff out. A saw turns trees into planks. An internal combustion engine turns gasoline into rotational energy.
Version: 1CC BY-SA 4.0
C programming, Variables
Version: 1CC BY-SA 4.0
Now that we can create variables, let's learn how to fill those variables with input from the user. Like the output functions from [Simple output]( these input functions are declared in stdio.h, part of the C standard library. ## Input using scanf() The scanf() function is the input method equivalen
Version: 1CC BY-SA 4.0
Its type depends on its form and value. The types of constants are character constants (e.g. ' ' is a space), integer constants (e.g. 2), floating-point constants (e.g.
Version: 1CC BY-SA 4.0
C programming, Arrays and strings
Version: 1CC BY-SA 4.0
C programming, Program flow control
Version: 1CC BY-SA 4.0
In C programming, all executable code resides within a **function**. Note that other programming languages may distinguish between a "function", "subroutine", "subprogram", "procedure", or "method" -- in C, these are all functions. Functions are a fundamental feature of any high level programming la
Version: 1CC BY-SA 4.0
A library in C is a collection of header files, exposed for use by other programs. The library therefore consists of an interface expressed in a .h file (named the "header") and an implementation expressed in a .c file. This .c file might be precompiled or otherwise inaccessible, or it might be avai
Version: 1CC BY-SA 4.0
Why doesn't it work? ### Data types - List at least three data types in C On your computer, how much memory does each require? - Which ones can be used in place of another? Why?
Version: 1CC BY-SA 4.0
In the chapter [Variables]( we looked at the primitive data types. However, more advanced data types allow us greater flexibility in managing data in our program. ## Structs Structs are data types made of variables of other data types (possibly including other structs). They are used to group pieces
Version: 1CC BY-SA 4.0
C programming, Pointers and arrays
Version: 1CC BY-SA 4.0
In the presence of side effects, a program's behaviour may depend on history; that is, the order of evaluation matters. Understanding and debugging a function with side effects is more difficult, requiring knowledge about the context and its possible histories.[1][2] ## Sequence points A **sequence
Version: 1CC BY-SA 4.0
In C, you have already considered creating variables for use in the program. You have created some arrays for use, but you may have already noticed some limitations: - the size of the array must be known beforehand - the size of the array cannot be changed in the duration of your program Dynamic mem
Version: 1CC BY-SA 4.0
C does not provide direct support for error handling (also known as exception handling). By convention, the programmer is expected to prevent errors from occurring in the first place, and test return values from functions. For example, -1 and NULL are used in several functions such as socket() (Unix
Version: 1CC BY-SA 4.0
FORTRAN II was touted as a machine-independent language in the 1960s, yet it was essentially impossible to move a FORTRAN program between architectures without some change. In FORTRAN II, you named the device you were talking to right in the FORTRAN statement in the middle of your FORTRAN code. So,
Version: 1CC BY-SA 4.0
A **string** in C is merely an array of characters. The length of a string is determined by a terminating null character: '\0'. So, a string with the contents, say, "abc" has four characters: 'a', 'b', 'c', and the terminating null ('\0') character. The terminating null character has the value zero.
Version: 1CC BY-SA 4.0
The header contains prototypes for several functions that deal with mathematics. In the 1990 version of the ISO standard, only the double versions of the functions were specified; the 1999 version added the float and long double versions. To use these math functions, you must link your program with

Support this publication

Monthly, through Stripe. After Stripe's fee and Hub Nexus's 14%, half of each payment goes to the curators and half to the authors of the pages in it, by how many pages each wrote.