Professional Documents
Culture Documents
Contents
Contents
Fundamentals of C
Contents
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Where are we?
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Introduction
What is „C‟?
„C‟ is a programming language developed at AT&T‟s Bell
Laboratories of USA in 1972. It was designed and written by
Dennis M. Ritchie.
Where are we?
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Basics of Algorithm
What is an Algorithm?
An algorithm is a step by step procedure for solving a problem.
Basics of Algorithm
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a ‘C’ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Structure of a ‘C’ program
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a ‘C’ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Compilation and Execution of a C Program
1. #include<stdio.h>
2. #include<conio.h>
3. main()
4. {
5. clrscr();
6. printf(“Hello! Welcome to C!”);
7. getch();
8. }
Fig:-First.c
Source File Header File
#include<stdio.h>
STDIO.H
First.C #include<conio.h>
CONIO.H
Compiler
Linker
Hello! Welcome to C!
Fig:-First.c
1. #include<stdio.h>
2. #include<conio.h>
3. #include<math.h>
4. main()
5. {
6. int a=25,b;
7. clrscr();
8. b=sqrt(a);
9. printf(“Square Root is %d”,b);
10. getch();
11. }
Fig:-First.c
Source File Header File
#include<stdio.h>
STDIO.H
First.C #include<conio.h>
CONIO.H
MATH.H
Compiler
Linker
Square Root is 5.
Fig:-First.c
Where are we?
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Character Set, Tokens, identifiers, keywords,
constant and escape sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Character Set, Tokens, identifiers, keywords,
constant and escape sequences
int marks;
float area;
void add();
Character Set, Tokens, identifiers, keywords,
constant and escape sequences
What are keywords?
Keywords are reserved words whose meaning has already been
explained to C compiler.
There are 32 keywords available in C.
Character Set, Tokens, identifiers, keywords,
constant and escape sequences
Hi
How are you?
Byelo
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Tokens, identifiers, keywords, constant and escape
sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Data types, Variables, Operators and Expressions
What is a Variable?
A variable is a name given to memory location in computer
where we can store constant values.
Data types, Variables, Operators and Expressions
Introduction
Basics of Algorithm, Flowchart and examples……
Structure of a „C‟ program
Tokens, identifiers, keywords, constant and escape
sequences.
Data types, Variables, Operators and Expressions
Operators continued & programs
Compilation & Execution
Data types, Variables, Operators and Expressions
What is an Operator?
An operator is a symbol that represent an operation.
Example
+ symbol represents addition
* symbol represent multiplication
What is an Expression?
An expression is a combination of variable, constants and operators.
Example
(a+b)
(a+b-10)
(a+10)*b
(m+n)*c
(a*b)/c
(a+b)*(c+d)
Data types, Variables, Operators and Expressions
1. Arithmetic Operator
There are 5 arithmetic operators
Data types, Variables, Operators and Expressions
Data types, Variables, Operators and Expressions
Data types, Variables, Operators and Expressions
2. Relational Operators
Relational operators are used to compare two values or
expression.
Sr. No. Example Result
1 25<30
2 3<2
3 3<3
4 25<=90
5 25<=25
6 25<=10
7 2>1
8 2>34
9 3>3
10 3>=3
11 3>=1
12 3>=5
13 3==3
14 3==2
15 3!=2
16 3!=3
Sr. No. Example Result
1 25<30 True
2 3<2 False
3 3<3 False
4 25<=90 True
5 25<=25 True
6 25<=10 False
7 2>1 True
8 2>34 False
9 3>3 False
10 3>=3 True
11 3>=1 True
12 3>=5 False
13 3==3 True
14 3==2 False
15 3!=2 True
16 3!=3 False
Data types, Variables, Operators and Expressions
3. Logical Operator
Sometimes we need to test more than one condition at a time
and make a decision depending upon the result.
Logical operators are used to combine two or more expression
(usually relational expression). The entire expression is called
logical expression which evaluate to either true (1) or false (0).
Data types, Variables, Operators and Expressions
Data types, Variables, Operators and Expressions
5. Assignment Operator
The assignment operator is represented by =. It is used to
assign value to the variable. Value can be assigned
to variable using the assignment operator as given
below,
5. Assignment Operator
Data types, Variables, Operators and Expressions
6. Conditional Operator
The conditional operator is in combination of ?:.
The conditional operators ? and : are sometimes called ternary
operators since they need three arguments. Their general form is,
7. Bitwise Operator
Bitwise operators are used to manipulate data at bit level.
They can operate only on ints and chars but not on floats
and doubles.
Data types, Variables, Operators and Expressions
Examples,
Left shift Operator(<<)
int a=5,b;
b=a<<1;
Right shift Operator(>>)
int a=5,b;
b=a>>1;
One‟s Compliment Operator(~)
int a=5,b;
b=~a;
Data types, Variables, Operators and Expressions
Examples,
Bitwise And Operator(&)
int a=5, b=4,c;
c=a&b;
Bitwise Or Operator (|)
int a=5, b=4,c;
c=a|b;
Bitwise Xor Operator (^)
int a=5, b=4,c;
c=a^b;
Data types, Variables, Operators and Expressions
8. Other Operators
Sizeof Operator
The sizeof operator gives/returns the size (in bytes) of the data-type
or variable or constant. The format is,
sizeof(int); returns 2.
sizeof(float); returns 4.
sizeof(10); returns 2.
Data types, Variables, Operators and Expressions
8. Other Operators
Comma Operator
The comma operator is represented by ,. It is used to separate a
set of expressions. A pair of expressions separated by a comma
is evaluated left to right.
Example,
i=(j=3,j+2);
Data types, Variables, Operators and Expressions
9. Address Operator
The address operator when used with a variable returns the
address of variable.
Example,
b=&a;