Basics of the C Programming Language: Keywords, Functions, and Operators
Unlike a human language, C has no declensions or cases. You’ll find no masculine, feminine, or neuter. And you never need to know what the words pluperfect and subjunctive mean. You do have to understand some of the lingo, the syntax, and other mischief.
Forget nouns, verbs, adjectives, and adverbs. The C language has keywords. Unlike human languages, where you need to know at least 2,000 words or so to be somewhat literate, the C language sports a scant vocabulary: Only a handful of keywords exist, and you may never use them all.
These keywords represent the C language’s basic commands. These simple directions are combined in various interesting ways to do wondrous things. But the language doesn’t stop at keywords.
Don’t bother memorizing the list of keywords.
The keywords are all case-sensitive.
Of the 44 keywords, 32 are original C language keywords. The C99 update (in 1999) added five more, and the more recent C11 (2011) update added seven. Most of the newer keywords begin with an underscore, as in _Alignas.
Keywords are also known as reserved words, which means that you cannot name functions or variables the same as keywords. The compiler moans like a drunken, partisan political blogger when you attempt to do so.
Where you find only 44 keywords, there are hundreds (if not thousands) of functions in the C language, including functions you create. Think of a function as a programming machine that accomplishes a task. Truly, functions are the workhorses of the C language.
The telltale sign of the function is the appearance of parentheses, as in puts() for the puts function, which displays text. Specifically, puts means “put string,” where string is the programming lingo for text that’s longer than a single character.
Functions are used in several ways. For example, a beep() function may cause a computer’s speaker to beep:
Some functions are sent values, as in
Here, the string Greetings, human. (including the period) is sent to the puts() function, to be sent to standard output or displayed on the screen. The double quotes define the string; they aren’t sent to standard output. The information in the parentheses is said to be the function’s arguments, or values. They are passed to the function.
Functions can generate, or return, information as well:
value = random();
The random() function generates a random number, which is returned from the function and stored in the variable named value. Functions in C return only one value at a time. They can also return nothing. The function’s documentation explains what the function returns.
Functions can also be sent information or return something:
Functions can also be sent information as well as return something:
result = sqrt(256);
The sqrt() function is sent the value 256. It then calculates the square root of that value. The result is calculated and returned, stored in the result variable.
A function in C must be defined before it’s used. That definition is called a prototype. It’s necessary so that the compiler understands how your code is using the function.
You’ll find lists of all the C language functions online, in what are called C library references.
Function prototypes are held in header files, which must be included in your source code.
The functions themselves are stored in C language libraries. A library is a collection of functions and the code that executes those functions. When you link your program, the linker incorporates the functions’ code into the final program.
As with keywords, functions are case sensitive.
Mixed in with functions and keywords are various symbols collectively known as operators. Most of them are mathematic in origin, including traditional symbols like the plus (+), minus (–), and equal (=) signs.
Operators get thrown in with functions, keywords, and other parts of the C language; for example:
result = 5 + sqrt(value);
Here, the = and + operators are used to concoct some sort of mathematical mumbo jumbo.
Not all C language operators perform math.