All About C Programming
Introduction to c-
C is a structured, procedural programming language that has been widely used both for operating systems and applications and that has had a wide following in the academic community.
Many versions of UNIX-based operating systems are written in C.
Programming Language -
Before learning any language, it is important to know about the various types of language and their features. It is interesting to know what were the basic requirement of the programmer and what difficulties they faced with the existing language The programming language can be classified into two types-
1. Low Level Language
2. Machine Level Language
Low Level Language -
The language in this category are the Machine level language and Assembly language.
Machine Level Language-
Computers can understand only digital signals, which are in binary digits 1.c. 0 and 1.
So the instructions given to the computer can be only in binary codes. The machine language consists of instructions that are in binary 0 or 1.
Computers can understand only machine level language.
Assembly Language-
The difficulties faced in machine level language were reduced to
some extent by using a modified form of machine level language called assembly language.
In assembly language instructions are given in English like words, such as MOV, ADD, SUB etc.
So it is easier to write and understand assembly programs Since a computer can understand only machine level language,
hence assembly language program must be translated into machine language.
The translator that is used for translating is called "assembler".
High-Level Languages -
High-level languages are designed keeping in mind the features of portability i.e. these languages are machine independent. These are English like languages, so it is easy to write and understand the programs of high-level language. While programming in a high level language, the programmer is not concerned with the low level details, and so the whole attention can be paid to the logic of the problem being solved. For translating a high-level language program into machine language, compiler or interpreter is used. Every language has its own compiler or interpreter. Some languages in this category are- FORTRAN,
COBOL, BASIC, Pascal etc.
Translators -
We know that computers can understand only machine level language, which is in binary 1 or 0. It is difficult to write and maintain programs in machine level language. So the need arises for converting the code of high-level and low-level languages into machine level language and translators are used for this purpose. These translators are just computer programs, which accept a program written in high level or low-level language and produce an equivalent machine language program as output. The three
types of translators used are-
. Assembler
.Compiler
.Interpreter
Assembler
Assembler is used for converting the code of low-level language (assembly language) into machine level language.
Compilers and interpreters
Compiler and interpreter are used to convert the code of high-level language into machine language. The high level program is known as source program and the corresponding machine language program is known as object program. Although both compilers and interpreters perform the same task but there is a difference in their working.
compiler
A compiler searches all the errors of program and lists them. If the program is error free then it converts the code of program into machine code and then the program can be executed by separate commands.
Interpreter
An interpreter checks the errors of program statement by statement. After checking one statement, it converts that statement into machine code and then executes that statement. This process continues until the last statement of program or an erroneous statement occurs.
Data Types -
Most of the time, for small programs, we use the basic fundamental data types in C – int, char, float, and double. For more complex and huge amounts of data, we use derived types – array, structure, union, and pointer.
Constant -
A constant is a name given to the variable whose values can't be altered or changed. A constant is very similar to variables in the C programming language, but it can hold only a single variable during the execution of a program.
Numeric Constants -
Numeric constants consist of numeric digits, they may or may not have decimal point(. ).
These are rules for defining numeric constants
1. Numeric constant should have at least one digit.
2. No comma or space is allowed within the numeric constant.
3. Numeric constants can either be positive or negative but default sign is always positive.
There are two types of numeric constants
Integer constant-
Integer constants are whole numbers which have no decimal point (.). There are three types of integer
stunts based on different number systems. The permissible characters that can be used in these constants are:
Decimal constants - 0,1,2,3,4,5,6,7,8,9 (base 10)
Octal constants- 0,1,2,3,4,5,6,7 (base 8)
Hexadecimal constants - 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f (base 16)
Same valid decimal integer constants are:
0
123
3705
23759
Real (floating point) Constants -
Floating point constants are numeric constants that contain decimal point. Some valid floating point constants are:
0.5
5.3
4000.0
0.0073
5597
39.0807
Character Constants -
A character constant is a single character that is enclosed within single quotes. Some valid character constants are-
'9' 'D' '$' '#'
String Constants -
A string constant has zero, one or more than one character. A string constant is enclosed within double quotes (" "). At the end of string, \0 is automatically placed by the compiler.
Some examples of string constants are-
"Kumar"
"593"
"8"
"A"
Note that "A" and 'A' are different, the first one is a string constant which consists of character A and \0 while the second one is a character constant which represents integer value 65.
Variables -
Variable is a name that can be used to store values. Variables can take different values but one at a time. These values can be changed during execution of the program. A data type is associated with
each variable. The data type of the variable decides what values it can take. The rules for naming variables
are same as that for naming identifiers.
Declaration of Variables -
When a variable is declared it contains undefined value commonly known as garbage value. If we want we can assign some initial value to the variable during the declaration itself, this is called initialisation
of the variable. For example -
int a = 5;
float x = 8.9, Y = 10.5;
char ch = 'y';
double num = 0.15197e-7;
int 1, m, n, total = 0;
In the last declaration only variable total has been initialised.
c in depth book click here
THANK YOU!
Comments
Post a Comment