C Language

Developed originally at Bell Labs by Ken Thompson and Dennis Ritchie in the second half of the 1980’s, the C Language has become a high-level programming language responsible for almost all operating systems of today. Together with the object-oriented successor of C, C++, these two languages have become commercial software’s first choice in programming language. UNIX runs on C Language and is becoming commercially acceptable on a mass scale.

Venture capital seems to be financing C Language-based software development as it is gaining interest in the job market and receiving support from large corporations and big business markets. Communications and Information Technology are some of the employment opportunities available for the expert C Language programmer.

Like any language learning exercise, the C Language begins with Variables and Constants. These Variables and Constants of basic data types create words and sentences of C, forming the C programming language. A set of instructions and rules for writing in the C Language exists, as is part of any computer programming language. These instructions are explained in online tutorials defining Statements, Expressions, Operators, Managing Input/Output Operations, Strings, Arrays, Functions, Pointers, Dynamic Memory allocation and more.

Using Preprocessor directives, Macros, define identifier string, Simple macro substitution, Macros as arguments, Nesting of macros, Un-defining a macro and File inclusion, the C Language programmer becomes familiar with the terms and functions of this complex programming language. The preprocessor in the C Language is examined in tutorials that describe modifying and reading C Language and discuss efficiency and portability.

This tutorial will give you an overview of the C programming language. We will cover some of the history of C, why people use it, where it is being used, and the basic structure of programs in C. History The C language was developed at AT&T Bell Labs in the early 1970s by Dennis Ritchie. It was based on an earlier Bell Labs language “B” which itself was based on the BCPL language. Since early on, C has been used with the Unix operating system, but it is not bound to any particular O/S or hardware. C has gone through…

This tutorial will cover constants and identifiers in C. Constants, as the name implies, are values that never change. In the previous tutorial on data types you have seen how a variable can be declared constant by making use of the const keyword. You can also declare a constant by directly entering its value in the source code. For example, in this code: double pi = 3.14159; char c = ‘A’; char hello[] = “Hello World!”; The number 3.14159, the letter A and the string Hello World! are all constants. You have already seen these types of constants used in…

C language provides various data types for holding different kinds of values. There are several integral data types, a character data type, floating point data types for holding real numbers and more. In addition you can define your own data types using aggregations of the native types. The C standard gives detailed specifications on the language; implementations of C must conform to the standard. An “implementation” is basically the combination of the compiler, and the hardware platform. As you will see, the C standard usually does not specify exact sizes for the native types, preferring to set a basic minimum…

C programming language provides several operators to perform different kind to operations. There are operators for assignment, arithmetic functions, logical functions and many more. These operators generally work on many types of variables or constants, though some are restricted to work on certain types. Most operators are binary, meaning they take two operands. A few are unary and only take one operand. Operators can be classified based on the type of operations they perform. C Arithmetic Operators Arithmetic operators include the familiar addition (+), subtraction (-), multiplication (*) and division (/) operations. In addition there is the modulus operator (%)…

Expressions in C are basically operators acting on operands. Statements like a = b + 3, ++z and 300 > (8 * k) are all expressions. Strictly speaking, even a single variable or constant can be considered an expression. You have seen several expressions in the previous C tutorial on Operators in which the examples involved expressions. Precedence and Associativity When an expression can be interpreted in more than one way, there are rules that govern how the expression gets interpreted by the compiler. Such expressions follow C’s precedence and associativity rules. The precedence of operators determine a rank for…

Input Output operations are useful for program that interact with user, take input from the user and print messages. The standard library for input output operations used in C is stdlib. When working with input and output in C there are two important streams: standard input and standard output. Standard input or stdin is a data stream for taking input from devices such as the keyboard. Standard output or stdout is a data stream for sending output to a device such as a monitor console. To use input and output functionality in your program, you need to include stdio header:…

“Decision making” is one of the most important concepts of computer programming. Programs should be able to make logical (true/false) decisions based on the condition they are in; every program has one or few problem/s to solve; depending on the nature of the problems, important decisions have to be made in order to solve those particular problems. In C programming “selection construct” or “conditional statement” is used for decision making. Diagram 1 illustrates “selection construct”. Diagram 1 simple selection construct Conditional statement is the term used by many programming languages. The importance of conditional statements should not be ignored because…

Loops are group of instructions executed repeatedly while certain condition remains true. There are two types of loops, counter controlled and sentinel controlled loops (repetition). Counter controlled repetitions are the loops which the number of repetitions needed for the loop is known before the loop begins; these loops have control variables to count repetitions. Counter controlled repetitions need initialized control variable (loop counter), an increment (or decrement) statement and a condition used to terminate the loop (continuation condition). Sentinel controlled repetitions are the loops with an indefinite repetitions; this type of loops use “sentinel value” to indicate “end of iteration”….

Array is a collection of same type elements under the same variable identifier referenced by index number. Arrays are widely used within programming for different purposes such as sorting, searching and etc. Arrays allow you to store a group of data of a single type. Arrays are efficient and useful for performing operations . You can use them to store a set of high scores in a video game, a 2 dimensional map layout, or store the coordinates of a multi-dimensional matrix for linear algebra calculations. Arrays are of two types single dimension array and multi-dimension array. Each of these…

In this tutorial you will learn about Initializing Strings, Reading Strings from the terminal, Writing strings to screen, Arithmetic operations on characters, String operations (string.h), Strlen() function, strcat() function, strcmp function, strcmpi() function, strcpy() function, strlwr () function, strrev() function and strupr() function. In C language, strings are stored in an array of char type along with the null terminating character "\0" at the end. In other words to create a string in C you create an array of chars and set each element in the array to a char value that makes up the string. When sizing the string…

Types of Functions You may have noticed the discussion about the <data type> portion of the function declaration missing from the last section. The <data type> refers to the type of data that would be returned by the function when it finishes executing. Data types are the same as any variable data types plus another one called void. Void type functions do not return any values. Function with no arguments and no return value: void function_name(); Think of this as a self-contained block of reusable code that does not need any data from the outside or have to return any…

The concept of functions in C language is the same as for any other programming language. Few languages have methods but, since there are no classes in C, methods are not used. Functions are best used for reusable code, or code that you know works and do want make use of it throughout development. If you find yourself tempted to use copy and paste on a particular block of code, even once, then you should move the code into a function. Lets talk about the different types of variables before diving into functions as it is a bit of a…

In this tutorial you will learn about C Programming – Structures and Unions, initializing structure, assigning values to members, functions and structures, passing structure to functions, passing entire function to functions, arrays of structure, structure within a structure and union. Structures are slightly different from the variable types you have been using till now. Structures are data types by themselves. When you define a structure or union, you are creating a custom data type. Structures Structures in C are used to encapsulate, or group together different data into one object. You can define a Structure as shown below: struct object…

Pointers are widely used in programming; they are used to refer to memory location of another variable without using variable identifier itself. They are mainly used in linked lists and call by reference functions. Diagram 1 illustrates the idea of pointers. As you can see below; Yptr is pointing to memory address 100. Diagram 1: 1. Pointer and memory relationship Pointer Declaration Declaring pointers can be very confusing and difficult at times (working with structures and pointer to pointers). To declare pointer variable we need to use * operator (indirection/dereferencing operator) before the variable identifier and after data type. Pointer…

Embedded and other low-memory footprint applications need to be easy on the amount of memory they use when executing. In such scenarios, statically sized data types and data structures just are not going to solve your problem. The best way to achieve this is by allocation of memory for variables at runtime under your watchful eye. This way your program is not using more memory than it has to at any given time. However, it is important to note that the amount of memory that can be allocated by a call to any of these functions is different on every operating…

In this tutorial you will learn about C Programming – Linked Lists, Structure, Advantages of Linked List, and Types of linked list and Applications of linked lists. Linked lists are a type of data structure for storing information as a list. They are a memory efficient alternative to arrays because the size of the list is only ever as large as the data. Plus they do not have to shift data and recopy when resizing as dynamic arrays do. They do have the extra overhead of 1 or 2 pointers per data node, so they make sense only with larger…

C Programming – File management in C In this tutorial you will learn about C Programming – File management in C, File operation functions in C, Defining and opening a file, Closing a file, The getw and putw functions, The fprintf & fscanf functions, Random access to files and fseek function. C supports a number of functions that have the ability to perform basic file operations, which include: 1. Naming a file 2. Opening a file 3. Reading from a file 4. Writing data into a file 5. Closing a file Real life situations involve large volume of data and…

C Language – The Preprocessor In this tutorial you will learn about C Language – The Preprocessor, Preprocessor directives, Macros, #define identifier string, Simple macro substitution, Macros as arguments, Nesting of macros, Undefining a macro and File inclusion. The Preprocessor A unique feature of c language is the preprocessor. A program can use the tools provided by preprocessor to make his program easy to read, modify, portable and more efficient. Preprocessor is a program that processes the code before it passes through the compiler. It operates under the control of preprocessor command lines and directives. Preprocessor directives are placed in…

In C programming language, variables can be referred differently depending on the context. For example, if you are writing a program for a low memory system, you may want to avoid copying larger sized types such as structs and arrays when passing them to functions. On the other hand, with data types like integers, there is no point in passing by reference when a pointer to an integer is the same size in memory as an integer itself. Now, let us learn how variables can be passed in a C program. Pass By Value Passing a variable by value makes…

Concept of Pixel in C Graphics Pixel is otherwise called as picture elements. These are nothing but small dots. Using these tiny dots or in other words pixels images especially graphics images are built on screen. If all pictures are built by concept of pixel then wondering how each picture differ that is how some picture appear more brighter while some other have a shady effect. All this is by the concept or technically terminology called as resolution. So let’s have an insight on this important terminology. Resolution is the number of rows that appear from top to bottom of…

What does TSR stands for? TSR stands for Terminate- and Stay-Resident programs What’s Special about TSR! As the name says Terminate-and-Stay-Resident TSR are programs which get loaded in memory and remain or stay there (resident) in memory permanently. They will be removed only when the computer is rebooted or if the TSR is explicitly removed from memory. Until then they will stay (resident) in memory active Working Technology of TSR Nothing happens because of TSR occupying place in memory. In other words when TSR is not running it does not affect the running of other DOS programs. It stays in…

In this tutorial you will learn about C Programming – What is Doubly linked lists, Adding Nodes Doubly linked lists, Traversing a Doubly linked lists and working with Doubly linked list Example. Doubly linked lists are the same as singly linked lists, except they have an extra pointer per node so they point to the next node and the previous node. You just make sure that whenever you insert a node you set next to the next node and previous to the previous node. They will also commonly keep a tail and head pointer so that traversal may start at…

In this tutorial you will learn about C Programming – What is Circular Linked List, Adding Nodes to Circular Linked Lists, Traversing a Circularly Linked List and working with Circularly Linked List Example. Circular linked lists are usually used for a queue or stack type situation, or for implementing a round robin algorithm in system level programming. You could also use one for a multiplayer game where you were keeping track of player’s turns where it just repeats until the game ends. They are exactly the same as a singly linked list, but instead of setting the next pointer in…

Structure A struct is an aggregate type, meaning that it is made up of other objects. The objects that make up a struct are called its members. The members of a struct may be accessed by the ‘.’ or ‘->’ operators. A struct may be named or unnamed. Let’s look at some examples: #include struct person { char first[100]; char last[100]; int age; struct { char addrline[500]; char city[100]; char state[30]; char zip[15]; } address; }; void printperson( struct person *p ) { printf( “%s…