2. History
C is a structured programming language developed by
Dennis Ritchie in 1973 at Bell Laboratories.
C programming language features were derived from
an earlier language called “B”.
C language was invented for implementing UNIX
operating system.
Today's most popular Linux OS and RBDMS MySQL
have been written in C.
3.
4. Features
Simple
Portable
Structured programming language
Rich library
Memory Management
Speed
Pointer
Recursion
Middle level language
6. Basic Structure of ‘C’ (Cont.)
Documentation Section :-
It has set of comment lines(name of program, author
details).
Non-executable statement.
Can’t be nested.
eg. /* Program to find factorial of a number
By: Smith */
/* Welcome /* friends */ ! */ Illegal
7. Basic Structure of ‘C’ (Cont.)
Link Section :-
It provides instructions to the compiler to link function
from the system library.
# include Directive:- It tells the preprocessor to insert
the contents of another file into the source code at the
point where the #include directive is found.
stdio– Standard Input /Output
conio– Console input/Output
math- contains mathematical functions like(cos(), sin(),
sqrt(), abs())
Eg. #include<stdio.h>
8. Basic Structure of ‘C’ (Cont.)
Definition Section :-
It defines all symbolic constants.
eg. #define PI 3.14
It’s not a statement. Therefore it should not end with a
semicolon.
Generally written in uppercase.
9. Basic Structure of ‘C’ (Cont.)
Global Declaration Section :-
Two types of declarations:
1.) Local variable declaration
2.) Global variable declaration
Global variables are declared out side the main
function. Scope of variable is whole program.
Local variables are declared inside the main function.
Scope of variable is the function in which it is declared.
10. Basic Structure of ‘C’ (Cont.)
main() function Section :-
Every C program must have one main function section.
Two parts,
1) Declaration part: It declares all the variables used in
the executable part.
2) Executable part: It contains instructions to perform
certain task.
11. Basic Structure of ‘C’ (Cont.)
Subprogram Section :-
It contains body of user defined function.
Eg. int sum (int a, int b)
{
int c;
c=a+b;
return c;
}
12. Example 1
/*Documentation Section: Program to find the area of
circle*/
#include <stdio.h> /*link section*/
#include <conio.h>/*link section*/
#define PI 3.14 /*definition section*/
float area; /*global declaration section*/
void main()
{
float r; /*declaration part*/
printf("Enter the radius of the circlen"); /*executable
part starts here*/
15. Tokens
A token is either a keyword, an identifier, a constant, a
string literal, or a symbol.
Eg. printf("Hello, World! n");
The individual tokens are:
printf
(
"Hello, World! n"
)
;
16. Semicolons(;)
It is a statement terminator.
Each individual statement must be ended with a
semicolon.
It indicates the end of one logical entity.
Eg.
printf("Hello, World! n");
return 0;
or
printf("Hello, World! n"); return 0;
17. Comments
Comments are like helping text in your C program and
they are ignored by the compiler.
Single line comment: //first program in c
Multiline comment: /* first
program
in
C */
18. Identifiers
A C identifier is a name used to identify a variable,
function, or any other user-defined item.
An identifier starts with a letter A to Z or a to z or an
underscore _ followed by zero or more letters,
underscores, and digits (0 to 9).
C does not allow punctuation characters such as @, $,
and % within identifiers.
C is a case sensitive programming language.
Eg. int money;
Here, money is identifier.
20. Keywords
They are reserved words in C.
These reserved words may not be used as constant or
variable or any other identifier names.
Eg. int money;
Here, int is keyword.
21.
22. Whitespace
Whitespace describes blanks, tabs(t), newline(n)
characters.
Whitespace separates one part of a statement from
another and enables the compiler to identify where one
element in a statement, such as int, ends and the next
element begins.
Eg. int age;