
2). C Programming Language
In computing, C is a general-purpose programming language initially developed by Dennis Ritchie between 1969 and 1973 at AT&T Bell Labs.[4] Its design provides constructs that map efficiently to typical machine instructions, and therefore it found lasting use in applications that had formerly been coded in assembly language, most notably system software like the Unix computer operating system. C is one of the most widely used programming languages of all time, and there are very few computer architectures for which a C compiler does not exist.
C has a formal grammar specified by the C standard.[14] Unlike languages such as FORTRAN 77, C source code is free-form which allows arbitrary use of whitespace to format code, rather than column-based or text-line-based restrictions. Comments may appear either between the delimiters /* and */, or (since C99) following // until the end of the line.
C source files contain declarations and function definitions. Function definitions, in turn, contain declarations and statements. Declarations either define new types using keywords such asstruct, union, and enum, or assign types to and perhaps reserve storage for new variables, usually by writing the type followed by the variable name. Keywords such as char and int specify built-in types. Sections of code are enclosed in braces ({ and }, sometimes called "curly brackets") to limit the scope of declarations and to act as a single statement for control structures.
As an imperative language, C uses statements to specify actions. The most common statement is an expression statement, consisting of an expression to be evaluated, followed by a semicolon; as a side effect of the evaluation, functions may be called and variables may be assigned new values. To modify the normal sequential execution of statements, C provides several control-flow statements identified by reserved keywords. Structured programming is supported by if(-else) conditional execution and by do-while, while, and for iterative execution (looping). The forstatement has separate initialization, testing, and reinitialization expressions, any or all of which can be omitted. break and continue can be used to leave the innermost enclosing loop statement or skip to its reinitialization. There is also a non-structured goto statement which branches directly to the designated label within the function. switch selects a case to be executed based on the value of an integer expression.
Developed at AT &T Bell Laboratory in 1970’s
Designed by Dennis Ritchie
Salient features of C
1. General Purpose, structured programming language
2. It can considered as High lavel language, however as it combines both the features, it can be treated as a Middle level languge
3. Portable
4. easy to debug
5. Easy to test and maintain
3) Structure of a C program
Documentations
The documentation section consist of a set of comment lines giving the name of the program, the another name and other details, which the programmer would like to use later. Preprocessor Statements
The preprocessor statement begin with # symbol and are also called the preprocessor directive. These statements instruct the compiler to include C preprocessors such as header files and symbolic constants before compiling the C program. Some of the preprocessor statements are listed below. Global Declarations
The variables are declared before the main ( ) function as well as user defined functions are called global variables. These global variables can be accessed by all the user defined functions including main ( ) function.
The main ( ) function
Each and Every C program should contain only one main ( ). The C program execution starts with main ( ) function. No C program is executed without the main function
Local Declarations
The variable declaration is a part of C program and all the variables are used in main ( ) function should be declared in the local declaration section is called local variables. Not only variables, we can also declare arrays, functions, pointers etc. These variables can also be initialized with basic data types. For example.
Code:
Main ( )
{
int sum = 0;
int x;
float y;
}
User defined functions
These are subprograms, generally, a subprogram is a function and these functions are written by the user are called user ; defined functions. These functions are performed by user specific tasks and this also contains set of program statements. They may be written before or after a main () function and called within main () function. This is an optional to the programmer. Now, let us write a small program to display some message shown below.
Code:
# include <stdio.h>
main()
{
printf ("welcome to the world of C/n");
}
Example
/* Program to add two numbers */
#include <stdio.h>
main()
{
int a,b,sum;
printf(“Enter the values of a and b:\n”);
scanf(“%d,%d”,&a,&b);
sum = a+b;
printf(“the sum is %d”, sum);}
4) C Character Set
The basic C source character set includes the following characters:
Letters: a–z, A–Z, _
Digits: 0–9
Punctuation: ~ ! @ # % ^ & * ( ) - + = : ; " ' < > , . ? | / \ { } [ ]
Whitespace characters: space, horizontal tab, vertical tab, form feed, newline
Newline indicates the end of a text line; it need not correspond to an actual single character, although for convenience C treats it as one.
Additional multibyte encoded characters may be used, but are not portable. The latest C standard (C11) allows multinational Unicode characters to be embedded portably within C source text by using a \uDDDD encoding (where DDDD denotes a Unicode character code), although this feature is not yet widely implemented.
The basic C execution character set contains the same characters, along with representations for alert, backspace, and carriage return. Run-time support for extended character sets has increased with each revision of the C standard.
5). Identifiers
An Identifier is a name for a variable, type, type member, template, class, function,namespace etc and is usually limited to letters, digits and underscores. Certain words are reserved and cannot be used as identifiers such as new.
Computer languages often have restrictions on what characters may appear in an identifier. For example, in early versions of the C and C++ languages, identifiers were restricted to being a sequence of one or more ASCII letters, digits (these may not appear as the first character), and underscores. Later versions of these languages support almost all Unicode characters in an identifier (usually these do not allow white space characters and language operators).
For implementations of programming languages that are compiled, identifiers are often only compile time entities. That is, at runtime the compiled program contains references to memory addresses and offsets rather than the textual identifier tokens (these memory addresses, or offsets, having been assigned by the compiler to each identifier).
Keywords
Reserved words that have standard, predefined meaning in C language.
These are used for intended purpose only, these cannot be used as programmer –defined identifiers.
Examples: auto, break, case, switch, for, goto, struct etc….
6) DATA types.declarations
In the C programming language, data types refers to an extensive system for declaring variables of different types. The language itself provides basic arithmetic types and syntax to build array and compound types. Several headers in the standard library contain definitions of support types, that have additional properties, such as exact size, guaranteed
Basic Data types
Data type |
Description |
Typical Memory Requirements |
Int |
Integer |
2 bytes or one word |
Char |
A character |
1 byte |
Float |
Decimal number |
4 bytes |
Double |
Double precision |
8 bytes |
char -> character
int -> integer
float -> float(single precision)
double -> float(double precision)
short -> short (16 bit integer)
long -> long (32 bit integer)
signed -> positive and negative
unsigned -> positive only
*int, *float, .. -> pointer to int, float, ..
const -> constant
enum -> enumeration constant
extern -> declare external variable
static -> local to source file
register -> register variable
void -> no value
struct -> structure
sizeof object -> size of an object (type is size_t)
sizeof (type name) -> size of a data-type (type is size_t)
typedef typename -> create name by data-type
7). Constants
A C constant is usually just the written version of a number. For example 1, 0, 5.73, 12.5e9. We can specify our constants in octal or hexadecimal, or force them to be treated as long integers.
Octal constants are written with a leading zero - 015.
Hexadecimal constants are written with a leading 0x - 0x1ae.
Long constants are written with a trailing L - 890L.
Character constants are usually just the character enclosed in single quotes; 'a', 'b', 'c'. Some characters can't be represented in this way, so we use a 2 character sequence as follows.
'\n' newline '\t' tab '\\' backslash '\'' single quote '\0' null ( Used automatically to terminate character string ) |
Character constants are rarely used, since string constants are more convenient. A string constant is surrounded by double quotes eg "Brian and Dennis". The string is actually stored as an array of characters. The null character '\0' is automatically placed at the end of such a string to act as a string terminator.
A character is a different type to a single character string. This is important poing to note.