C is mother language of all programming language.
It is a system programming language. It is a procedure-oriented programming language. It is also called mid-level programming language.
C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970. Ken used B to write one of the first implementations of UNIX. B in turn was a descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most of its instructions removed.
So many instructions were removed in going from BCPL to B, that Dennis Ritchie of Bell Labs put some back in (in 1972), and called the language C.
The famous book The C Programming Language was written by Kernighan and Ritchie in 1978, and was the definitive reference book on C for almost a decade.
The original C was still too limiting, and not standardized, and so in 1983, an ANSI committee was established to formalize the language definition.
It has taken until now (ten years later) for the ANSI ( American National Standard Institute) standard to become well accepted and almost universally supported by compilers.
3. What is c language:-
C is mother language of all programming
language.
It is system programming language.
It is procedure-oriented programming
language.
It is also called mid level programming
language.
4. A brief history of C
C evolved from a language called B, written by Ken Thompson at Bell Labs in 1970.
Ken used B to write one of the first implementations of UNIX. B in turn was a
descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most
of its instructions removed.
So many instructions were removed in going from BCPL to B, that Dennis Ritchie of
Bell Labs put some back in (in 1972), and called the language C.
The famous book The C Programming Language was written by Kernighan and
Ritchie in 1978, and was the definitive reference book on C for almost a decade.
The original C was still too limiting, and not standardized, and so in 1983 an ANSI
committee was established to formalise the language definition.
It has taken until now (ten years later) for the ANSI ( American National Standard
Institute) standard to become well accepted and almost universally supported by
compilers
5. Language year Developed By
ALGOL 1960 InternationalGroup
BPCL 1967 Martin Richards
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K & R C 1978 Kernighan &Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISOC 1990 ISO Committee
C99 1999 Standardization
Committee
Summary of C language history
6. Features ofC
The main features of C is; It is Structure oriented
programming languageand it isaverysimpleandeasy
languageztoreadandwrite,
9. IDE: The Integrated Development Environment
Turbo c features as integrated Development
environment, or IDE,. It is also referred to as the
programmer’s platform.) in IDE you can able to
write/save/open your programs or code, compile
using short cut keys, and also perform code
debugging very easily.
10.
11. Common Short cut Keys Description
F2 press to Save current work
F3 press to open an existing file
ALT-F3 press to close current
ALT-F9 press to compile only
ALT-F5 press to view the desired output of the
program.
CTRL-F9 press to compile+run
ALT-X or ALT-F-X press to exit from TC IDE
IDE: The Integrated Development Environment
12. C Programs STRUCTURE (General)
<Preprocessor Directives (some time necessary)>
<Macros Definition (optional)>
<function declaration>
< Global Variable (on your demand)>
main () (Necessary)
{ statements }
< function definition>
{ }
13. Remember Some common rules for writing C
program
Use all commands or statements in lower or small case.
After completion of a statement excluding main() or loops must
insert ; (semicolon) as a statement terminator.
Don’t use/declare identifier or variable name same as statement
name suppose int
include; this is a wrong statement because include has a special
meaning in the language.
16. Compiling & Executing C Programs
C compiler: This program translates the C language source code
into the machine assembly language.
Assembler: The assembler accepts the C – compiler output and
creates object code. If the program does not contain any external
function calls, this code is directly executable.
Linker: If a source file references library functions, which is
defined in other source files, the linker combines these functions
with the main() function to create an executable program file.
17. C Program: Steps
Step 1: The program that is to be compiled is first typed into a
file on the computer system. There are various conventions that
are used for naming files, typically be any name provided the last
two characters are “.c” or file with extension .c. So, the file name
prog1.c might be a valid filename for a C program. The program
that is entered into the file
is known as the source program because it represents the
original form of the program expressed in the C language.
18. C Program: Steps
Step 2: After the source program has been entered
into a file, then proceed to have it compiled.
Typical errors reported during this phase of
compilation might be due to an expression that has
unbalanced parentheses (syntactic error), or due to
the use of a variable that is not “defined” (semantic
error).
19. C Program: Steps
Step 3: When all the syntactic and semantic errors
have been removed from the program, the compiler
then proceeds to take each statement of the program
and translate it into a “lower” form that is equivalent
to assembly language program needed to perform
the identical task.
20. C Program: Steps
Step 4: After the program has been translated the
next step in the compilation process is to translate
the assembly language statements into actual
machine instructions. The assembler takes each
assembly language statement and converts it into a
binary format known as object code, which is then
written into another file on the system. This file has
the same name as the source file under Unix, with
the last letter an “o” (for object) instead of a “c”.
21. C Program: Steps
Step 5: After the program has been translated into
object code, it is ready to be linked. This process is
once again performed automatically whenever the cc
or gcc command is issued under Unix. The purpose
of the linking phase is to get the program into a final
form for execution on the computer.
22. C Program: Steps
Step 6: The final linked file, which is in an
executable object code format, is stored in another
file on the system, ready to be run or executed..
23. Header Files or Preprocessor Directives
C preprocessor: This program accepts C source files as input and
produces a file that is passed to the compiler.
The preprocessor is responsible for removing comments and interpreting
special C language pre-processor directives, which can be easily
identified as they begin with the # symbol.
# include: The preprocessor adds the information about the object code
used in the body of the main function. These files are called headerfiles.
# define: this directive assigns a symbolic name to a constant.
Symbolic names are used to make programs more readable and
maintainable.
24. Header Files or Preprocessor Directives
Header Files or Preprocessor Directives contains references or links of
library functions. That is built-in in the C language.
Suppose if you want to use a function clrscr() ; in the main function so must be
declared on top # include <conio.h> other wise you could have an prototype error.
Some header files are as follows
Stdio.h
Conio.h
Dos.h
String.h
math.h
And many more header files are available in C…
25. Main() function: void main(void)
Every C programs consists of one or more functions. No
matter how many functions there are in a C program , main
is the one to which control is passed from the operating
system when the program is run ; it is the first function
executed.
The word "void" preceding "main" specifies that the function
main() will not return a value.
The second "void," in parenthesis , specifies that the
function takes no arguments.
26. printf() function
printf() is built-in function we can display with
printf() any message, variable value on
screen/file/printer.
In printf() we can use many escape
sequences and format specifies.
27. First Program of C Language:-
#include <stdio.h>
#include <conio.h>
void main(){
printf("Hello CLanguage");
getch();
}
29. Describe theC Program:-
#include <stdio.h> includes the standard input
output library functions. The printf() function is defined in
stdio.h .
#include <conio.h> includes the console input
output library functions. The getch() function is defined in
conio.h file.
void main() The main() function is the entry point of
every program in c language. The void keyword specifies
that it returns no value.
printf() The printf() function is used to print data on the
console.
getch() The getch() function asks for a single
character. Until you press any key, it blocks the screen.
30. Escape sequences
Escape sequences are special notations through which we can display our data Variety of
ways:
Some escape sequences and their functions are as follows:
Perform line feed (new line ) & Carriage return operation printf("AnB");
Escape Sequence Description Example
n
t
’
“
r
b
Prints a tab sequence on screen printf ("Atb");
Prints a single quote character on screen printf ("’a’");
Prints a double quote character on Screen printf (""a"");
Perform carriage return operation printf ("arb")
Remove one character from left printf ("abHi!" );
31. Escape Sequence
Program of CLanguage:-
#include <stdio.h>
#include <conio.h>
void main(void)
{
clrscr();
printf( " " C Language" n");
getch();
}
Output:
" C Language "
33. Rules for Comment
Comments : code which are not executable statement, of
necessary can be placed in between /* and */.
Comment in the program should be enclosed within /* .. */ .Look example below
the first line is comment.
For ex. /*This my first program*/
#include<stdio.h>
main()
{
Statement;
Statement;
}
34. Rules for Comment
Though comments are not necessary, but it good practice to begin programwith
comment indicating purpose of program so that other person can get idea of
program.
You can write any number comment at any place in program mentioning the
purpose of the statement.
Use few Comment instead of too many.
A comment cannot be nested. For ex., /* The/*first/*program*/*/*/.
// use for single line comment and /* */ multiple line
A comment can split over more than one line. Forex.
/*THE
First
Program*/
37. C Programming Error Types – Runtime,
Compile & Logical Errors
While writing c programs, errors also known as bugs in the world
of programming may occur unwillingly which may prevent the
program to compile and run correctly as per the expectation of
the programmer.
Basically there are three types of errors in c programming:
Runtime Errors
Compile Errors
Logical Errors
38. C Runtime Errors
C runtime errors are those errors that occur during the
execution of a c program and generally occur due to some
illegal operation performed in the program.
Examples of some illegal operations that may produce
runtime errors are:
Dividing a number by zero
Trying to open a file which is not created
Lack of free memory space
39. Compile Errors
Compile errors are those errors that occur at the time of compilation
of the program. C compile errors may be further classified as:
Syntax Errors
When the rules of the c programming language are not followed,
the compiler will show syntax errors.
For example, consider the statement:
int a,b:
The above statement will produce syntax error as the statement is
terminated with : rather than ;
40. Compile Errors
Semantic Errors
Semantic errors are reported by the compiler when the
statements written in the c program are not meaningful to the
compiler.
For example, consider the statement,
b+c=a;
In the above statement we are trying to assign value of a in the
value obtained by summation of b and c which has no meaning
in c. The correct statement will be
a=b+c;
41. Logical Errors
Logical errors are the errors in the output of the
program. The presence of logical errors leads to
undesired or incorrect output and are caused due to
error in the logic applied in the program to produce the
desired output.
Also, logical errors could not be detected by the
compiler, and thus, programmers has to check the
entire coding of a c program line by line.