Language History
C – Language History
- C language is a structure oriented programming language, was developed at Bell Laboratories in 1972 by Dennis Ritchie
- C features were derived from earlier language called “B” (BCPL language)
- C was invented for implementing UNIX operating system
- In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C Programming Language” and commanly known as K&R C
- In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or “ANSI C”, was completed late 1988.
C standards
- C89/C90 standard – First standardized specification for C language was developed by American National Standards Institute in 1989. C89 and C90 standards refer to the same programming language.
- C99 standard – Next revision was published in 1999 that introduced new futures like advanced data types and other changes.
C11 and Embedded C
- C11 standard adds new features to C and library like type generic macros, anonymous structures, improved Unicode support, atomic operations, multi-threading, and bounds-checked functions. It also makes some portions of the existing C99 library optional, and improves compatibility with C++.
- Embedded C includes features not available in normal C like fixed-point arithmetic, named address spaces, and basic I/O hardware addressing
- Operating systems, C compiler, all UNIX application programs are written in C
- It is also called as procedure oriented programming language
- C language is reliable, simple and easy to use.
- C has been coded in assembly language
Features of C language:
- Reliability
- Portability
- Flexibility
- Interactivity
- Modularity
- Efficiency and Effectiveness
Uses of C language:
C is used for developing system applications that forms portion of
operating system. Below are some examples of C being used.
- Database systems
- Graphics packages
- Word processors
- Spread sheets
- Operating system development
- Compilers and Assemblers
- Network drivers
- Interpreters
Which level the C language belonging to?
S.no High LevelMiddle LevelLow Level1 High level languages provides almost everything that the programmer might need to do as already built into the language Middle level languages don’t provide all the built-in functions found in high level languages, but provides all building blocks that we need to produce the result we want Low level languages provides nothing other than access to the machines basic instruction set 2 Examples:Ada, BASIC, COBOL, FORTRAN,
Modula-2C, C++, JAVA, FORTH, Macro-Assembler Assembler C is a structured language
S.no Structure orientedObject orientedNon structure1 In this type of language, large programs are divided into small programs called functions In this type of language, programs are divided into objects There is no specific structure for programming this language 2 Prime focus is on functions and procedures that operate on data Prime focus is on the data that is being operated and not the functions or procedures N/A 3 Data moves freely around the systems from one function to another Data is hidden and cannot be accessed by external functions N/A 4 Program structure follows “Top Down Approach” Program structure follows “Bottom UP Approach” N/A 5 Examples:BASIC, COBOL, FORTRANC, C++, JAVA, Ada, Pascal, Modula-2Assembler Key points to remember:
- C is structured, middle level programming language developed by Dennis Ritchie
- Operating system programs such as Windows, Unix, Linux are wriiten by C language
- C89/C90 and C99 are two standardized editions of C
- C has been written in assembly language
Data Type in 'C'
Father of C - Dennis Ritchie
First Computer Programmer - Ada
Cut - shift + del
Paste - shift + insert
Copy - ctrl + insert
Clear - ctrl + del
Compile - alt + F9
Run - ctrl + F9
To see the output - alt + F5
1. Data Type in C
Data Type Meaning Size (in bytes)
char(Range -128 to +127) a character 1
int(Range -32768 to +32767) an integer 2
float a single precision real number 4
double a double precision real number 8
void valueless 0
(The void data type is not used as often as the above four.)
C Data Types
|
|--------------------------------------------|
Primary Data Types Secondary Data Types
1. Character 1. Array
i. Unsigned Char
ii. Signed Char
2. Integer 2. Pointer
i. Short
ii. Long
3. Float 3. Structure
4. Double 4. Union
5. Void 5. Enum etc.
Integers
- Integers data type can be categorised into two parts;Long and short.
- Long integers require twice the space in memory than ordinary integers do.
- Therefore long integers occupy four bytes of memory.
- The value of a long integer can vary form -2147483648 to +2147483647.
- Long integers declared using the keywords long. For example:
long int i;
- Short integers require less space in memory and thus speed up the program execution.
- Short integer is nothing but our ordinary int.
- Short integers are declared using keywords int. For example:
int i;
-
If we add the suffix 'L' or 'l' at the end of the number, then it would
be becoming as a long integer and hence occupy 4 bytes.
Constants and Variables
- A constant is a quantity that does not change. This quantity can be stored at a location in the memory of the computer.
- Real constants are often called Floating Point constants.
-
The real constants could be written in two forms; Fractional (426.0,
+325.34,-32.76) and Exponential (+3.2e-5, 4.1e8,-3.2e-5) Form.
- Range of real constant expressed in exponential form is -3.4e38 to 3.4e38.
- The part appearing before 'e' is called mantissa, whereas the part following 'e' is called exponential.
- In place of a small case 'e' a capital 'E' can also be used.
Rules for Constructing Variable Names
- A variable name is any combination of 1 to 8 alphabets, digits or underscores.
- Some compilers allow variables names whose length could be upto 40 characters. But it is recommended to stick on 8 characters.
- The first character in the variable name must be an alphabet.
- No commas, blanks or special character (except underscore) are allowed within a variable name.
Scope of Variables
- Variables can have two types of scopes: Local and Global.
-
A variable with a global scope is accessible to all the statements in
the program, whereas the one with local scope is available only to
certain selected statements in the program.
- Global variables are declared outside all functions whereas the local variables are defined inside a function.
C Keywords
- Keywords also known as 'Reserved Word'.
- Keywords are the words whose meaning has already been explained to the C compiler.
- The keywords cannot be used as variable names.
- There are 32 keywords available in C, for example: break, case, else, char, if, for, void etc.
C Programming
- A comment can be enclosed within /* */ (for multiple line comment) or // (for single line comment).
Printf(): It is a function which is used to print the value contained in a variable on the screen.
Syntax: printf("<format string">,<list of variable>);
<format string> could be %c (for character), %d(for integer),%f(for float values).
Example: printf("%d",n1);
/n: It is called a newline and takes the cursor to the next line.
Example: printf("Average=%d\nSum=%d",avg,sum);
Scanf(): It is used for supplying the values in the variables.
Syntax: scanf("<format string">,&<list of variable>);
Example: scanf("%d",&n1);
Integers, Signed & Unsigned
When
we know in advance that the stored value in a given integer variable
will always be positive, then we can declare the variable to be unsigned, as in;
unsigned int car_park;
With
such a declaration, the range of permissible integer values will shift
from the range -32768 to +32767 to the range 0 to 65535. Thus declaring
the integers as unsigned almost doubles the size of the largest possible
value. Unsigned integer occupies two bytes. The following unsigned
declarations are same;
short unsigned int i;
unsigned int i;
unsigned i;
The
way there exists a short unsigned int, there also exists a long
unsigned int which has a range of 0 to 4294967295 and occupies four
bytes of memory.
By default a short int is a signed short int and a long int is a signed long int.
Char, Signed & Unsigned
Signed and unsigned chars, both occupying one byte each, but having different range.
A
signed character is same as our ordinary char and has a range from -128
to +127; whereas an unsigned char has a range from 0 to 255.
#include<stdio.h>
void main
{
char ch=291;
printf(“%d%c\n”,ch,ch);
}
Output is
35 #
Since
variable ch has defined as char, therefore it cannot take a value
bigger than +128. But when value exceeds +127, an appropriate value from
the other side of the range is picked up and stored in ch. In this
case, value is 35 and its corresponding character is # get printed.
Program1:
#include<stdio.h>
void main()
{
char c;
unsigned char d;
int i;
unsigned int j;
long int k;
unsigned long int m;
float x;
double y;
scanf(“%c%c”,&c,&d);
printf(“%c%c”,c,d);
scanf(“%d%u”,&i,&j);
printf(“%d%u”,i,j);
scanf(“%ld%lu”,&k,&m);
printf(“%ld%lu”,k,m);
scanf(“%f%lf”,&x,&y);
printf(“%f%lf”,x,y);
getch();
}
No comments:
Post a Comment