Introduction to C:
The programming language C was developed in the 1970s by Dennis Ritchie at Bell Labs (Murray Hill, New Jersey) in the process of implementing the Unix operating system on a DEC PDP-11 computer. C has its origins in the typeless programming language BCPL (Basic Combined Programming Language, developed by M. Richards) and in B (developed by K. Thompson). In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.
C is a highly portable language oriented towards the architecture of today’s computers. The actual language itself is relatively small and contains few hardware-specific elements. It includes no input/output statements or memory management techniques, for example. Functions to address these tasks are available in the extensive C standard
library.
C’s design has significant advantages:
i. Source code is highly portable
ii. Machine code is efficient
iii. C compilers are available for all current systems
Functions:
A C program consists of individual building blocks called functions, which can invoke one another. Each function performs a certain task. Ready-made functions are available in the standard library; other functions are written by the programmer as necessary. A special function name is main( ): this designates the first function invoked when a program starts. All other functions are subroutines.
Character Sets:
ANSI C defines two character sets. The first is the source character set, which is the set of characters that may be used in a source file. The second is the execution character set, which consists of all the characters that are interpreted during the execution of the program, such as the characters in a string constant. Each of these character sets contains a basic character set, which includes the following:
The 52 upper- and lower-case letters of the Latin alphabet:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
The ten decimal digits (where the value of each character after 0 is one greater than the previous digit): 0 1 2 3 4 5 6 7 8 9
The following 29 graphic characters:
· ! ” # % & ‘ ( ) * + , – . / : ;
< = > ? [ \ ] ^ _ { | } ~
The five whitespace characters:
space, horizontal tab, vertical tab, newline, form feed
In addition, the basic execution character set contains the following:
i.The null character \0, which terminates a character string
ii. The control characters represented by simple escape sequences, for controlling output devices such as terminals or printers.
Identifiers:
Identifiers are names of variables, functions, macros, types, etc. Identifiers are subject to the following formative rules:
1.An identifier consists of a sequence of letters (A to Z, a to z), digits (0 to 9), and underscores (_).
2.The first character of an identifier must not be a digit.
3. Identifiers are case-sensitive.
4. There is no restriction on the length of an identifier. However, only the first 31 characters are generally significant.
Keywords are reserved and must not be used as identifiers. Following is a list of keywords:
auto enum restrict(*) unsigned break extern return void case float short volatile char for signed while const goto sizeof _Bool(*) continue if static _Complex(*) default inline(*) struct _Imaginary(*) do int switch double long typedef else register union
Some examples of identifiers are:
Valid: a, DM, dm, FLOAT, _var1, topOfWindow,temp,n
Invalid: do, zähler, total-amount, 123_num
Categories and Scope of Identifiers:
Each identifier belongs to exactly one of the following four categories:
1. Label names
2. The tags of structures, unions, and enumerations. These are identifiers that follow one of the keywords struct, union, or enum.
3.Names of structure or union members. Each structure or union type has a separate name space for its members.
4. All other identifiers, called ordinary identifiers.
Identifiers of different categories may be identical. For example, a label name may also be used as a function name. Such re-use occurs most often with structures: the same string can be used to identify a structure type, oneof its members, and a variable;
for example:
struct student {char *student; /*...*/} student;
The same names can also be used for members of different structures.
Each identifier in the source code has a scope . The scope is that portion of the program in which the identifier can be used. The four possible scopes are:
Function prototype:
Identifiers in the list of parameter declarations of a function prototype (not a function definition) have function prototype scope . Because these identifiers have no meaning outside the prototype itself, they are little more than comments.
Function:
Only label names have function scope. Their use is limited to the function block in which the label is defined. Label names must also be unique within the function. The goto statement causes a jump to a labelled statement within the same function.
Block:
Identifiers declared in a block that are not labels have block scope. The parameters in a function definition also have block scope. Block scope begins with the declaration of the identifier and ends with the closing brace (}) of the block.
File:
Identifiers declared outside all blocks and parameter lists have file scope. File scope begins with the declaration of the identifier and extends to the end of the source file.
An identifier that is not a label name is not necessarily visible throughout its scope. If an identifier with the same category as an existing identifier is declared in a nested block, for example, the outer declaration is temporarily hidden. The outer declaration becomes visible again when the scope of the inner declaration ends.
Basic Types:
The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. Similarly, the type of a function determines how its return value is to be interpreted. Types can be either predefined or derived. The predefined types in C are the basic types and the type void. The basic types consist of the integer types and the floating types.
1 Integer Types:
There are five signed integer types: signed char, short int (or short), int, long int (or
long), and long long int(*) (or long long(*)). For each of these types there is a corresponding unsigned integer type with the same storage size. The unsigned type is designated by the prefix unsigned in the type specifier, as in unsigned int.
The types char, signed char, and unsigned char are formally different. Depending on the compiler settings, however, char is equivalent either to signed char or to unsigned char. The prefix signed has no meaning for the types short, int, long, and long long(*), however, since they are always considered to be signed. Thus short and signed short specify the same type. The storage size of the integer types is not defined; however, their width is ranked in the following order: char <= short <= int <= long <= long long(*). Furthermore, the size of type short is at least 2 bytes, long at least 4 bytes, and long long at least 8 bytes. Their value ranges for a given implementation are found in the header file limits.h. ANSI C99 also introduces the type _Bool to represent Boolean values. The Boolean value true is represented by 1 and false by 0. If the header file stdbool.h has been included, then bool can be used as a synonym for _Bool and the macros true and false for the integer constants 1 and 0.Three types are defined to represent non-integer real numbers: float, double, and long double. These three types are called the real floating types.
Internal representation of a real floating-point number:
The representation of a floating-point number x is always composed of a sign s, a mantissa m, and an exponent exp to base 2:
x = s * m * 2exp, where 1.0 <= m < 2 or m = 0
The precision of a floating type is determined by the number of bits used to store the mantissa. The value range is determined by the number of bits used for the exponent.For example, the number -2.5 = -1 * 1.25 * 21 is stored as:
S = 1, Exponent = 1+127 = 128, Mantissa = 0.25
C program to shift inputed data by two bits to the left
Parenthesis Checker(java implementation)

