









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










C OVERVIEW: C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC PDP-11 computer in 1972. In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard. The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C. C has now become a widely used professional language for various reasons ā
Easy to learn
Structured language
It produces efficient programs
It can handle low-level activities
It can be compiled on a variety of computer platforms Facts about C
C was invented to write an operating system called UNIX.
C is a successor of B language which was introduced around the early 1970s.
(^) The language was formalized in 1988 by the American National Standard Institute (ANSI).
The UNIX OS was totally written in C.
Today C is the most widely used and popular System Programming Language.
Most of the state-of-the-art software have been implemented using C.
Today's most popular Linux OS and RDBMS MySQL have been written in C. Why use C? C was initially used for system development work, particularly the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language. Some examples of the use of C might be ā
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities C PROGRAM STRUCTURE: Before we study the basic building blocks of the C programming language, let us look at a bare minimum C program structure so that we can take it as a reference in the upcoming chapters. Hello World Example A C program basically consists of the following parts ā
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
Let us look at a simple code that would print the words "Hello World" ā
Let us take a look at the various parts of the above program ā
Semicolons In a C program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. Given below are two different statements ā
Comments Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below ā
Identifiers A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9). C does not allow punctuation characters such as @, $, and % within identifiers. C is a case- sensitive programming language. Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers ā
Keywords
The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.
Whitespace in C A line containing only whitespace, possibly with a comment, is known as a blank line, and a C compiler totally ignores it. Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement ā
There must be at least one whitespace character (usually a space) between int and age for the compiler to be able to distinguish them. On the other hand, in the following statement ā
The array types and structure types are referred collectively as the aggregate types. The type of a function specifies the type of the function's return value. Integer Types: The following table provides the details of standard integer types with their storage sizes and value ranges ā
Floating-Point Types: The following table provides the details of standard floating-point types with storage sizes and value ranges and their precision ā
The void Type: The void type specifies that no value is available. It is used in three kinds of situations ā
A variable definition tells the compiler where and how much storage to create for the variable. A variable definition specifies a data type and contains a list of one or more variables of that type as follows ā
Here, type must be a valid C data type including char, w_char, int, float, double, bool, or any user-defined object; and variable list may consist of one or more identifier names separated by commas. Some valid declarations are shown here
Variable Declaration in C A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable. A variable definition has its meaning at the time of compilation only, the compiler needs actual variable definition at the time of linking the program.
OPERATORS: An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C# has rich set of built-in operators and provides the following type of operators ā
(1) Arithmetic Operators : Following table shows all the arithmetic operators supported by C#. Assume variable A holds 10 and variable B holds 20 then ā
(2) Relational Operators: Following table shows all the relational operators supported by C#. Assume variable A holds 10 and variable B holds 20, then ā
(4) Bitwise Operators: Bitwise operators work on bits and perform bit by bit operation. The truth tables for &, |, and ^ are as follows ā
Assume if A = 60; and B = 13; then in the binary format they are as follows ā A = 0011 1100 B = 0000 1101
A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011 The Bitwise operators supported by C# are listed in the following table. Assume variable A holds 60 and variable B holds 13, then ā