SlideShare a Scribd company logo
LANGUAGE
A language is a communication media
between two parties
Programming languages: A programming
language is a language used in writing
programs to direct processing steps to be
carried out by a computer.
Programming languages are
classified into 3 categories
1) Machine Language (or) Binary language
2. Assembly language
3) High level language
Machine level Language
 Machine code is the fundamental language of a computer
and is normally written as strings of binary 1’s and 0’s. The
circuitry of a computer is wired in such a way that it
immediately recognizes the machine language and converts
it into the electrical signals needed to run the computer.
 Programs written in machine language can be executed very
fast by the computer. This is mainly because the CPU
directly understands machine instructions and no translation
of the program is required.
 Advantages:- If we know this language we can directly
interact with the system, with out depending on any other
applications.
Assembly language
The language, which substitutes letters and symbols for
the numbers in the machine language program, is called
an assembly language or symbolic language. The
translator program that translates an assembly code into
the computer’s machine code is called assembler. The
assembler is a system program, which is supplied by the
computer manufacturer.
Advantages of Assembly language:
 Easier to understand and use
 Easy to locate and correct errors
 Easier to modify
 No worry about addresses
 Easily re locatable.
High level language
 Every instruction, which the programmer writes
in a high-level language, is translated into many
machine language instructions.
 While writing programs in any of the above
languages, a programmer has to remember all
the operation codes of the computer and now in
detail what each code does and how it affects the
various registers of the computers.
 These languages enable the programmer to write
instructions using English words and familiar
mathematical symbols.
Low level languages
They are machine dependent languages.
These are easily understood by computers.
The machine language and assembly
languages are examples of low level
languages.
Machine Languages
As the name implies, programming is done
at machine level. The vocabulary of
computer consists of only two words zero
and one. e.g., 10101011
Assembly Language
To overcome the drawbacks of the machine level
language, computer engineers developed new
programming language which uses symbolic
instructions. This symbolic instruction oriented
programming language is known as Assembly level
language.
E.g., ADD X,Y; Add the contents of y to x
Compiler Interpreter
1. Compiler converts all
statements at a time, if errors
are there, it displays all errors
as a list.
2. After Compiling the whole
program, if the program is
error free then it will execute
the program.
3. After Compilation, it creates
an executable file, using that
executable file we can run the
program any number of
times.
4. It is fast.
1. Interpreter converts line by
line, at the time of interpreting
any error is there, it displays
that error.
2. After interpreting the first line,
if it is error free then it will
execute that line.
3. It does not create any
executable file, every time we
need to interpret the program.
4. It is slow.
Differences between Compiler
and interpreter
 Programming : The art of writing instructions for
computer to solve the specific task is known as
programming. The output of programming is a
well defined set of instructions. This is called a
program.
 Algorithm
A sequence of language independent which may
be followed to solve a problem.
 Flowchart
Diagrammatic representation of step for solving
the given problem
Algorithm
Calculating area of a circle
1. Start
2. Input radius in cm
3. Calculate, area=3.14*(radius*radius)
4. Display
5. Stop
Flow Chart Symbols
Calculating area of a circle
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 a
man named Dennies Ritche.
Features of C
 Portability and machine Independent.
 Fast program execution.
 An extendible language.
 It is a structured programming language.
Programming in C
Character Set of C
Program
C Tokens
1. Alphabets
2. Numeric Digits
3. Special Characters
1. Constants
2. Variables
3. Keywords
4. Identifiers
Instructions
Character set of the
C language
This indicates group of characters which are useful to
write the programming statements. It contains 3 parts.
 Alphabets: C language supports upper case letters
(A to Z), lower case letters from (a to z). But both
are different. C is a case sensitive language.
 Numeric digits: C language contains the numeric
digits from 0 to 9.
 Special Characters: The characters other than
alphabets and numeric digits are called as special
characters.
Constants
It is a quantity which does not change its
value during executing a program.
Types of C constants
1. primary constants
2. Secondary constants
Types of Constants
Integer constants
Integer Constant: These are the numbers
without decimal point or exponent.
Ex:- int a=10;
Real Constants
Float constant: These are the numbers with
decimal point or exponent.
Ex:- float pie=3.14;
Character Constants
Single Character Constant: It is any one of
the single character enclosed in single
quotation.
Ex:- char ch=’a’;
char section=’b’;
String constant: Group of characters
enclosed with in double quotations.
Ex:- char name[20]= “Chandra”;
char nation[10]= “India”;
Variables
It is a name given to the memory location
which holds a particular data value that can
be change during the execution of the
program.
Variables are 4 types.
 Integer variables
 Float variables
 Single character variables
 String variables.
Local & global variables
1. Local variable - A variable declared inside a
function.
This variable can only be used in the function.
2. Global variable - A variable declared outside of
any functions.
This variable can be used anywhere in the
program.
Rules to write variable names
 It must not exceed 31 characters.
 A variable name includes alphabets and
numbers, but it must start with an alphabet.
 It cannot accept any special characters,
blank spaces except under score( _ ).
 It should not be a reserved word.
Identifiers
Identifiers are names given to various
program elements, such as variables,
functions and arrays.
key words(or)
Reserved words
Keywords are the words whose meaning
has already been explained to the C
compiler. The keywords cannot be used as
variable names.
auto
default
enum
if
short
switch
Volatile
const
continue
break
do
extern
int
signed
typedef
While
goto
return
case
double
float
long
sizeof
Union
struct
void
unsigned
char
else
for
register
static
There are 32 keywords available in C
Data types
Data type Range Bytes Format
signed char -128 to +127 1 %c
unsigned char 0 to 255 1 %c
short signed int -32,768 to +32,767 2 %d
short unsigned
int
0 to 65,535 2 %u
long signed int -2147483648 to
+2147483647
4 %ld
long unsigned int 0 to 4294967295 4 %lu
Float -3.4e38 to +3.4e38 4 %f
Double -1.7e308 to +1.7e308 8 %lf
long double -1.7e4932 to 1.7e4932 10 %lf
Input and Output functions
1. Formatted I/O functions
Input function – scanf()
Output function – printf()
2. Unformatted I/O functions
Input function – gets()
Output function – puts()
Formatted I/O functions
Output Function
printf( ): This function is used to display the
information on the screen. It displays the
variable values and the string values. This
function belongs to stdio.h.
Syntax: printf(“control_string” ,variable_list);
Examples:-
int a=10;
printf(“The value of a is %d”,a);
float pie=3.14;
printf(“The value of pie is %f”,pie);
char ch=‘A’;
printf(“Ch = %c”, ch);
char name[20]=“ORBIT”
printf(“Name = %s”, name);
Input function
scanf( ):- It is an input function, that is used
to accept the input from the keyboard(user)
at the time of executing a program. This
function belongs to stdio.h .
Syntax: scanf(“control_string”, variable_list);
Examples:-
int a;
scanf(“%d”, &a);
float b;
scanf(“%f”,&b);
char ch;
scanf(“%c”,&ch);
char name[20];
scanf(“%s”,name);
Unformatted I/O functions
Output function
puts()
This function is used to execute only string
values.
Syntax:- puts(string_variable);
Ex:- char name[20]=“ORBIT”;
puts(name);
Input function
gets()
This function is used to accept only string
values.
Syntax:- gets(string_variable);
Ex:- char name[20];
gets(name);
Writing C Programs
 A programmer uses a text editor to create or
modify files containing C code.
 Code is also known as source code.
 A file containing source code is called as source
file.
 After C source file has been created, the
programmer has to invoke C compiler in order
to execute (run) the program.
Structure of a C program
/* Comment line section */  Documentation
optional
# header file section  when we use
predefined functions
main( )
{
Declaration part;  To declare the
variables which are
used in the program
Initialization part;  To initialize i.e. giving
values to the variables
Execution part;  To execute as output
}
Comment Line Section
In order to give documentation for a
program comment line is includes. It is
enclosed in between a /* */ because in
the compilation process these lines are not
includes.
Comments are two types
Single line comment - // ------------
Multi line comment - /* -----------
-----------*/
Header file section
‘C’ program consists of predefined
functions for that reason we should
include the files in which they are
defined. Which are saved with .h as
extension.
Ex:- # include <stdio.h>
stdio.h stands for standard input
output . header file
# - It is used to tell the preprocessor to
get the header file to included in the
source code.
Include - it is used to include header file
specified in your source code.
 When we write our programs, there are libraries of
functions to help us so that we do not have to
write the same code over and over.
 Some of the functions are very complex and long.
Libraries of functions make it easier and faster to
write programs.
 Using the functions will also make it easier to learn
to write a program.
stdio.h
Main( )
 The compilation and the running process is done
with the help of Main( ). Every program must have
a function called main. This is where program
execution begins.
 main() is placed in the source code file as the first
function for readability.
 The parentheses following the reserved word
“main” indicate that it is a function.
Declaration part
This area is where we declare all the
variables which are used in the program.
Initialization part
Here, we give values to the declared
variables.
Executable part
The output is seen from the executable
part. By using output functions.
getch()
It is a predefined function available in <conio.h>
library which reads the character from the
keyboard without printing on the monitor.
getche()
It is a predefined function available in <conio.h>
library which reads the character from the
keyboard with printing on the monitor.
clrscr()
It is a predefined function available in <conio.h>
library which clears the previous contents of user
screen window.
Execution of C Program
Steps to be followed in writing and running a C program.
 Creation of Source Program
Create a C program code in Turbo C Editor.
 Compilation of the Program
Press Alt + F9 for compilation.
 Program Execution
In Turbo C environment, the RUN option will do the
compilation and execution of a program.
Press Ctrl + F9 for execution of the program.
Operators
 Arithmetic operators
 Relational operators
 Logical operators
 Assignment operators
 Increment or decrement operators
 Conditional operators
 Sizeof Operator
 Bitwise Operator
Arithmetic Operators
Arithmetic operators are used to perform
arithmetic operations like addition,
subtraction, multiplication, division and
remainder.
Operator Name Meaning Example
+ Plus Addition a+b
- Minus Subtraction a-b
* Asterisk Multiplication a*b
/ Slash Division a/b
% Modulator Reminder a%b
Relational operators
These operators are used to check the relation between
the values.
Note:- When we used relational operators the output is
seen in the form of 0 or 1. If the relation is true the output
will be in 1. If the relation is false the output will be 0.
Ex:- a=10
b=5
Operator Example Result
> a>b 1
< a<b 0
>= a>=b 1
<= a<=b 0
= = a==b 0
!= a!=b 1
Logical operators
logical operators are used to combine two
or more relational expressions. C language
contains 3 logical operators.
Operator Name
&& And
|| Or
! Not
&& : (And)
Statement:- When all arguments are true
then only the total condition is true. Any one
of the arguments is false the total condition
is false.
Expressinn1 && Expression2 Result
T T T
T F F
F T F
F F F
Truth table
|| : (Or)
Statement:- When one of the argument is
true the total condition is true. If all the
arguments are false then only the
condition is false.
Expression1 || Expression2 Result
T T T
T F T
F T T
F F F
Truth table
! (Not)
Statement:- This is the negative operator,
we can place the ‘not’ operator before any
one of the condition. It returns the opposite
result of the condition. i.e. It converts true
to false and false to true.
! expression result
T F
F T
Truth table
Assignment operator
C language contains equal to (=)
operator to assign a value or
expression into a variable.
Ex:- a=10;
b=a+10;
Increment and decrement
operators
1. Increment operator (+ +)
Increment operator is used to increase the value by 1.
 Pre Increment( ++a)
First the value will be incremented, and then the
new value will be executed.
Ex:- printf(“%d”,++a);
 Post Increment(a++)
First the value will be executed and then one value
will be incremented.
Ex:- printf(“%d”,a++);
2) Decrement operator ( - - )
Decrement operator is used to decrease the
value by 1.
 Pre Decrement (--a)
If the value is decreased before execution it is
called as pre decrement.
Ex:- printf(“%d”,--a);
 Post Decrement (a--)
If the value is decreased after the execution it is
called as post decrement.
Ex:- printf(“%d”,a--)
Conditional operators
C language contains conditional operators (?, : ). By
using conditional operators we can get the output in the
form of statements also. ? and : are called as
conditional or ternary operators.
Syn:- (condition) ? printf(“value 1”) : printf(“ value 2”);
Ex:- (a>b) ? printf(“a greater than b”):printf(“a is
less than b”);
If the condition is true then value1 will be executed, if
the condition is false then value2 will be executed.
Size of Operator
This operator is used to find memory size
of the variable or datatype.
Syntax:- sizeof(variable or datatype);
Complement operator (~)
It gives the ones complement of the
number.
 Add one to the given number
 Change it's sign
Bitwise operators
Bitwise operators compares internal binary
format of the number. These operators are
applicable in between integer variables only.
 Bitwise AND &
 Bitwise OR |
 Bitwise XOR ^
 Bitwise Left shift <<
 Bitwise Right shift >>
A B & | ^
----------------------------------------------
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
----------------------------------------------------
Ex:- int a=10,b=8,c;
c=a&b;
10 : 1 0 1 0
8 : 1 0 0 0
---------------------------
c : 1 0 0 0 Answer=8
c=a|b;
10 : 1 0 1 0
8 : 1 0 0 0
---------------------------
c : 1 0 1 0 Answer=10
c=a^b;
10 : 1 0 1 0
8 : 1 0 0 0
---------------------------
c : 0 0 1 0 Answer=2
Bitwise Left shift operator (<<)
Bitwise Left shift operator shifts the number of bits
toward left side specified number of times and fills
right side bit with zero.
Or
Multiply the given number by specified number of
powers of 2.
int a=10,b;
b=a<<1; a*2=10*2=20
b=a<<2; a*2*2=10*2*2=40
b=a<<3; a*2*2*2=10*2*2*2=80
Bitwise Right shift operator (>>)
Bitwise right shift operator shifts the number of bits
towards right side specified number of times and fills
left side bits with zero.
Or
Divide the given number by specified number of of
powers of 2.
int a=10,b;
b=a>>1; a/2=10/2=5
b=a>>2; a/(2*2)=10/(2*2)=2
b=a>>3; a/(2*2*2)=10/(2*2*2)=1
PRECEDENCE OF OPERATORS
(Arithmetic operators only)
Operator Description Associativity
*
/
%
+
-
Multiplication
Division
Modulo
Addition
Subtraction
Left to right
“
“
“
“
Conditional statements
The statements which are executed
according to some condition are called
as conditional statements.
They are 3 types
 If
 If-else
 Nested if-else
The If statement
Statement: This statement is used to perform
conditional operations.
Syntax:
if(condition)
{
statement;
}
If the condition is true then statement will be
executed. If the condition is false then it will not
execute statement.
Flow chart
if(condition)
Statement(s);
Next statements(if any)
False
True
If-else
The general form of if-else statement is…
Syntax:
if(condition)
{
statement1;
}
else
{
statement2;
}
If the condition is true then statement1 will be executed, if
the condition is false then statement2 Will be executed.
Flow chart
Statement(s);
Next statements(if any)
Statement(s);
if(condition)
False
True
Nested if-else
When a series of conditions are involved, we can use more
than one if-else statement in nested form.
Syntax:
if (condition)
{
statements;
}
else if (condition)
{
statements;
}
else
{
statements;
}
Switch statement
It is used to execute one of the options from no. of options. It is
also called as multi branching statement.
Switch (expression)
{
case value:
statements;
case value:
statements;
default:
statements;
}
The expression value may be int or character type. The switch
statement evaluates the expression. It will select one of the cases
based on expression. It will execute default statements when no
case is selected.
Break statement
 This control statement can be used in loops and switch
statements.
 It is used to terminate the loop when a specified condition
is satisfied.
 The control comes out of the loop and the following
statements are executed.
 In switch statements, the control comes out of the switch
statements and the following statements are executed.
Switch case
Syntax: switch(expression)
{
case 1:
{
statement;
}
break;
case 2:
{
statement;
}
break;
default:
{
statement;
}
}
Flow chart
switch(expression)
Case 1:
Match ? Statement(s); break;
case 2:
Match ? Statement(s); break;
case n:
Match ? Statement(s); break;
default Statement/s;
Next statement
The exit( ) Function
 The exit( ) is a function in the standard
library of C.
 This function causes immediate
termination of the program and execution
control returns to the operating system.
Control Statements
Unconditional control statements:
 goto statement
 break statement
 continue statement
Looping/Repetitive/Iteration control statements:
 for statement
 while statement
 do-while statement
Goto statement
Syntax:
goto label;
.
.
label :
Statement(s);
This is an unconditional control statement to tell the
compiler from where the next statements has to be
executed.
In other words, program control directly Jumps to
some location in a program with the help of this
statement.
Continue statement
 This control statements are used in the
loops.
 During execution if a continue statement
is encountered all the following
statements will be terminated and the
control will go to the next iteration of the
loop without executing the following
statements in the loop.
Loop control structures
LOOPING:- The process of executing a
block of code repeatedly is called as looping.
They are 4 types
 For loop
 While loop
 Do while loop
 Nested for loops
All the four loops are used for same process but
there syntax is different.
All the four loops have 3 steps is common.
 Initialization:- It is the starting point of the loop
process.
 Condition:- In this step logical test is applied. It
is true the block of code is executed. Till the
condition fails.
 Increment / Decrement:- In order to proceed or
stop the loop increment or decrement is
required.
For loop
It is used to execute a set of statements
repeatedly as long as the given condition is true.
Syntax:-
for (initial value ; test condition ; increment /decrement)
{
statements; //body of for loop
}
Ex:- for(i=1; i<=10; i++)
For loop
It is used to execute a set of statements
repeatedly as long as the given condition is true.
Syntax:-
for (initial value ; test condition ; increment /decrement)
{
statements; //body of for loop
}
Ex:- for(i=1; i<=10; i++)
Initialization expression
Test expression
Body of the loop
Update expression
Next statements (if any)
False
True
Flow chart
While loop
It is used to execute a set of statements
repeatedly as long as the given condition is true.
Syntax:- while (condition)
{
statements; //body of while loop
}
First the condition is tested, if it is true the body of
the while loop will be executed first time, again
the control is transferred back to while loop and
checks the condition, If it is false the control will
come out of the while loop.
Flow chart
while
(condition)
Statement(s);
Next statements (if any)
False
True
Do While Loop
This statement executes a set of statements as
long as the condition is true.
Syntax: do
{
statements;
statements;
}
while(condition);
This is similar to while loop, but the difference is
this loop will execute the statements at least once.
Statement/s;
Next statements(if any)
do
while
(condition);
True
Flow chart
Nested for loop
In order to get the output in the form of
rows and columns we use nested for
loops. If the outer loop condition is true
it enters into the inner loop. Till the
outer loop condition is false the looping
process is continued.
ARRAYS
An array is contiguous area in the memory
referred by a common name. The array allows
the storage of a number of data values in one
variable. Each array element i.e. each
individual data item is referred by specifying the
array name followed by one or more subscripts.
Each subscript is enclosed with square
brackets. Each subscript indicates the position
of the element in the array. Arrays are divided
into 2 types.
1. Single dimensional array or One dimensional
array
2. Two dimensional array
One dimensional array
The array which is using only 1 subscript is
known as one dimensional array. In one
dimensional array the elements are
represented in single row or single column.
Syntax:- Data_type variable_name[subscript]
Ex:- int a[5]={40, 50, 70,90,100};
Float b[4]={20.5, 40.9, 45.7, 23.8};
Char c[5]={‘O’,’R’,’B’,’I’,’T’};
Multi dimensional array
The array which is using two subscripts is known
as 2 – dimensional array
Syntax:-
Data_type variable_name [subscript][subscript]
Ex:- int a[2][2]={{1,2,},{3,4}};
The above declaration states that ‘a’ is an two
dimensional Array variable in which the values
are stored in 2 rows and in 2 columns
String Functions
A character array is defined as a string. A
group of characters is called a string. We
cannot handle with string same like integers
or real values. For example, if you want to
compare an integer value with another int
value. We can do that by using = =
operator. But the same procedure cannot
be applied for strings. In order to handle
with strings there are some string handling
functions.
Strlen( )
This function is used to find the length
of a string.
Syntax:- strlen(string);
Note:- When we are using string
functions we have to include a header
file <string.h>
Strcpy( )
This function copies a string from
one string variable to another string
variable.
Syntax:-
strcpy(target_string , source_string);
Strcat( ):- (String concatenation)
This function adds a string at the end
of another string
Syntax:- strcat(string1,stirng2);
Strcmp( ):- (String comparison)
This compares one string with
another string.
Syntax:-
strcmp(string1, string2);
Stricmp( )
This function is similar to strcmp, but
this function ignores the case
sensitivity.
Syntax:-
stricmp(string1, string2);
Strrev( )
This function reverses the given
string.
Syntax:- strrev(string);
Strupr( )
This function converts the given
string into upper case (capital letters)
Syntax:- strupr(string);
Strlwr( )
This function converts the given
string into lower case.
Syntax:- strlwr(string);
Single character
1) toupper( ) :- This function converts a single
character to upper case.
Syntax:- toupper(character);
2) tolower( ) :- This function converts a single
character to lower case.
Syntax:- tolower(character);
 Note:- when we are using single character
functions we have to include a header file
<ctype.h>
Functions
A function is a set of statements that
performs a specific task. Functions
are 2 types
1. Pre defined functions or Standard
functions
2. User defined functions
Pre defined Functions
These functions which are already
defined (in built) along with C are
called as pre defined functions.
Ex:-
printf( ), scanf( ), pow( ), strlen( ),
strcpy( ), toupper( ),……
User defined functions
These functions defined by the user in
order to work with complex program and
to develop the efficiency of the program
are called as user defined functions. In
order to define a function we have 3 types.
• Function definition
• Function prototype
• Invoking a function
Function definition
 Function heading
• Return type
• Function name
• Specification of parameters
a. Return type:- Return is called as data
type mention according to the type of
value returned from the function.
Note:- When there is no return statement
we should mention void as a default
return type.
b. Function name:- Here we mention the
name of a function. It is just like a
variable name
C. Specification of parameters:- The specify
the number of values are variables taken by
the called function from main program.
Note:-The parameters mentioned in the
main program for calling a function are
called as actual parameters.
The parameters mentioned in the function
which are received from the main program
are called formal parameters.
 Block of code
The code which is written with in the
braces of a function is called as block of
code.
 Return statement
This is the last statement of a function it is
to return a value from the user defined
function to the main program.
It is declared in the main program about the
function.
Note:- Function prototype is optional if the
function is defined before the main. It is
compulsory if the function is defined after
the main.
Function Prototype
Invoking a Function
From here we call the function. A
function as no live when it is not
Invoked.
Uses of functions
 Dividing the task into sub tasks.
 If a particular task is repeated number of times in a
program we can create a function and call that
function wherever we want.
 Whenever a function is called in a statement the
control will be transferred to that called function. After
executing all statements it returns back to the calling
function.
 The length of the source program will be reduced by
using functions at appropriate places.
 A function can be used in other programs also.
Syntax of a function / function definition
Return_type function_name (argument list)
{
declarations;
statements;
-------------
return value;
}
Function declaration
Return_type function_name (argument list);
Recursive function
Pointers
Pointer is a memory location or a variable which
stores the memory address of another variable in
memory
Pointers are much more commonly used in C &
C++ than in many other languages (such as
BASIC, Pascal, and certainly Java, which has no
pointers).
Problem solving using C++
What are pointers for?
Here are some common uses:
• Accessing array elements
• Passing arguments to a function when the
function needs to modify the original argument
• Passing arrays and strings to functions
• Obtaining memory from the system
• Creating data structures such as linked lists
Memory map
i
65524
‘i’ - Location name
10 - Value at location
65524 – Location number or address.
Declaration of a pointer:
Int a, *x;
Float b, *y;
Char c, *z;
Pointer variable is same as normal variable. But a *
symbol is added before the variable.
10
Usage of pointers
As pointers work with addresses accessing through
addresses first then through a normal variable. When
the values are called with the help of address by a
function the modifications done to the variables
shows the reflection.
Indirectly we can get the value of a variable by using
*. So * is called as indirection operator. Whatever the
data type may be a pointer variable occupies only 2
bytes of memory.
Parameter passing mechanism
 Call by value
 Call by address
 Call by value:- When the function calls the
parameters by taking values the modifications
done to the parameters by the function doesn’t
reflect.
 Call by address:- When the parameters are
called by address the changes done to the values
within the function shows the reflection.
Structures
Structure is a user defined data type. A structure is
a collection of variables that is referenced under a
single name. A structure contains a number of
data types grouped together. These data types
may or may not be of the same type.
Definition of a structure: - Structure is a
collection of variables which are of dissimilar data
types.
Declaring a structure:-
struct <structure name>
{
structure element 1;
structure element 2;
---
structure element n;
};
structure variable;
Ex:- struct book
{
int pages;
char author[20];
float price;
};
 In the above declaration book is called Tag
name and pages, author, price are called as
data members of the structure
Declaring a variable for a structure
Ex:- struct book b;
Here, ‘b’ is a variable of a structure to
which we can give 3 details.
The data members of the structure are
called by the variable using ( . ) operator.
For example:- b.pages
b.author
b.price
Features of a structure
With the help of structure we can maintain a
data in a systematic order. We can handle a
structure within a structure. And also we can
call the structure variable through functions
and Arrays also can be implemented
through structures. Pointer to structure is
also possible.
Unions
A union is similar to structure, but the difference is
1. The size of the structure variable is sum of all the
members size, but union size is the maximum
member's size.
2. In structure we can see all members at
a time, but in union we can see only one
member at a time because when we store
the second member, first value will be
over written.
Files
File is a collection of data to be stored
permanently in the disk space. The
disk may be either hard disk or floppy
disk or compact disk
Difference between Array and File
1.File is a collection of data. The data may be of
similar or dissimilar type.
Array is collection of elements of similar
datatype.
2. File size is unlimited.
Array size is limited.
3.File data is stored permanently in the disk
space.
Array data is stored temporarily in the RAM.
To Create a File pointer
FILE is a macro which is used to create
a file pointer which holds the address of
some file.
Syntax:- FILE * file_pointer;
Example:- FILE *fp;
To create or open the file
fopen()
It is a predefined function available in
<stdio.h> which is used to create or
open the file.
Syntax:-
file_pointer=fopen(filename,"Modes");
Modes are nothing but permissions to create
or open the file.There are 6 modes.
r:- fp=fopen(“Filename.extn","r");
If the file is already exist then it opens the
file with read permission.
r+ :- fp=fopen(“Filename.extn","r+");
If the file is already exist then it opens the
file with read and write permission.
W :- fp=fopen(“Filename.extn","w");
If the file is already exist then it opens the
file with write permission by deleting
previous data else creates the new file.
w+ :- fp=fopen(“Filename.extn","w+");
If the file is already exist then it opens the
file with read and write permission else
creates the new file.
a :- fp=fopen(“Filename.extn","a");
If the file is already exist then it opens
the file with add permission else
creates the new file.
a+ :- fp=fopen(“Filename.extn","a+");
It creats or opens the file with read
write and append permission.
To close the file
fclose()
It is a predefined function available in
<stdio.h> which is used to close the
specified file.
Syntax
fclose(file_pointer);
Example
fclose(fp);
getchar()
getchar() is a macro that gets a character
from stdin
Syntax: - int getchar(void);
putchar()
putchar() is a macro that outputs a
character on stdout
Syntax: -int putchar(int c);
getc()
getc() is a macro that gets one character
from a stream
Syntax: - getc(file_pointer);
putc()
putc() is a macro that outputs a character
to a stream
Syntax: - putc(character, file_pointer);
fputs()
fputs copies the null-terminated string s to the
given output stream. It does not append a
newline character, and the terminating null
character is not copied.
Syntax: - fputs(character, file_pointer);
fgets()
fgets reads characters from stream into the
string. It stops when it reads either n - 1
characters or a newline character, whichever
comes first.
Syntax: - fgets(character, file_pointer);
To write the character into the file
fputc()
It is a predefined function available in <stdio.h>
which is used to write the specified character into
the file.
Syntax
fputc(charactervariable,file_pointer);
Example
char ch='A';
fputc(ch,fp);
To read the character from the file
fgetc()
It is a predefined function available in <stdio.h>
which is used to read the character from file.
Syntax
charactervariable=fgetc(file_pointer);
Example
char ch;
ch=fgetc(fp);
To delete the file
remove()
It is a predefined function available in
<stdio.h> which is used to remove the
specified file.
Syntax
remove(filename);
Example
remove("Sachin");
To rename the file
rename()
It is a predefined function available in
<stdio.h> which is used to rename the file.
Syntax
rename(old filename,new file name);
Example
rename("Sachin","Mahesh");
To write the different types of data into the file
fprintf()
It is a predefined function available in <stdio.h>
which is used to write the different types of data
into the file .
Syntax
fprintf(file_pointer,"formatspecifier",variable);
Example
char c='@';
int i=10;
float f=34.56
fprintf(fp,"%d%c%f",i,c,f);
To read the different types of data from the file
fscanf()
It is a predefined function available in <stdio.h>
which is used to read the different types of data from
the file .
Syntax
fscanf(file_pointer,"formatspecifier",Address of
variable);
Example
char c;
int i;
float f;
fscanf(fp,"%d%c%f",&i,&c,&f);
storage classes
They are 4 types
1) automatic storage class
2) register storage class
3) static storage class
4) external storage class
Automatic storage class
The features of a variable defined to have an
automatic storage class are as under
 Storage : Memory
 Default initial value : Garbage value
 Scope : Local to block in which the variable is
defined
 Life : Till the control within the block in which
the variable is defined
Register storage class
 Storage : CPU registers
 Default initial value : Garbage value
 Scope : Local to block in which the
variable is defined
 Life : Till the control within the block in
which the variable is defined
Static storage class
 Storage : Memory
 Default initial value : Zero
 Scope : Local to block in which the
variable is defined
 Life : Value of the persists between
different function calls
External storage class
 Storage : Memory
 Default initial value : Zero
 Scope : Global
 Life : As long as the program execution
doesn't come to an end

More Related Content

What's hot (10)

PDF
A paper on finding d rsines from aryabhatiya bhasya by bhaskara i
Venkatesha Murthy
 
PPTX
Parallel sorting algorithm
Richa Kumari
 
PPTX
Code Optimization
Akhil Kaushik
 
PPTX
Possible Word Representation
chauhankapil
 
PPTX
Directed Acyclic Graph Representation of basic blocks
Mohammad Vaseem Akaram
 
PPTX
halstead software science measures
Deepti Pillai
 
PDF
Displacement addressing
Rajon
 
PPTX
C++ io manipulation
Pedro Hugo Valencia Morales
 
PPTX
Bezier Curves
Arundhati Kanungo
 
PPTX
Data Types and Variables In C Programming
Kamal Acharya
 
A paper on finding d rsines from aryabhatiya bhasya by bhaskara i
Venkatesha Murthy
 
Parallel sorting algorithm
Richa Kumari
 
Code Optimization
Akhil Kaushik
 
Possible Word Representation
chauhankapil
 
Directed Acyclic Graph Representation of basic blocks
Mohammad Vaseem Akaram
 
halstead software science measures
Deepti Pillai
 
Displacement addressing
Rajon
 
C++ io manipulation
Pedro Hugo Valencia Morales
 
Bezier Curves
Arundhati Kanungo
 
Data Types and Variables In C Programming
Kamal Acharya
 

Similar to C Lang notes.ppt (20)

PDF
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
PDF
Unit 2 introduction to c programming
Mithun DSouza
 
PPTX
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
GauravRawat830030
 
PDF
C programming introduction for beginners.pdf
sagarduari1
 
PDF
C programme presentation
DharmaKumariBhandari
 
PDF
Programming in c
ankitjain851
 
PDF
Unit 1
TPLatchoumi
 
PPTX
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
PDF
C programming language tutorial for beginers.pdf
ComedyTechnology
 
PPT
Unit 1 c - all topics
veningstonk
 
DOCX
C notes
Raunak Sodhi
 
DOCX
Lect '1'
reena0098
 
PPTX
cunit1.pptx
zeenatparveen24
 
PDF
C programming.pdf
JitendraYadav351971
 
PDF
C lecture notes new
Kuntal Bhowmick
 
PDF
C_NOTES.pdf
mechanicaleng2
 
PPTX
Copy of UNIT 2 -- Basics Of Programming.pptx
rahulrajbhar06478
 
PPTX
Msc prev completed
mshoaib15
 
PPTX
Msc prev updated
mshoaib15
 
PDF
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
C language for Semester Exams for Engineers
Appili Vamsi Krishna
 
Unit 2 introduction to c programming
Mithun DSouza
 
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
GauravRawat830030
 
C programming introduction for beginners.pdf
sagarduari1
 
C programme presentation
DharmaKumariBhandari
 
Programming in c
ankitjain851
 
Unit 1
TPLatchoumi
 
C programming slide day 01 uploadd by md abdullah al shakil
Zenith SVG
 
C programming language tutorial for beginers.pdf
ComedyTechnology
 
Unit 1 c - all topics
veningstonk
 
C notes
Raunak Sodhi
 
Lect '1'
reena0098
 
cunit1.pptx
zeenatparveen24
 
C programming.pdf
JitendraYadav351971
 
C lecture notes new
Kuntal Bhowmick
 
C_NOTES.pdf
mechanicaleng2
 
Copy of UNIT 2 -- Basics Of Programming.pptx
rahulrajbhar06478
 
Msc prev completed
mshoaib15
 
Msc prev updated
mshoaib15
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
Ad

Recently uploaded (20)

PPTX
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
PDF
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
PPTX
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
PPTX
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
PPTX
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PDF
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Explorando Recursos do Summer '25: Dicas Essenciais - 02
Mauricio Alexandre Silva
 
The-Beginnings-of-Indian-Civilisation.pdf/6th class new ncert social/by k san...
Sandeep Swamy
 
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
Views on Education of Indian Thinkers Mahatma Gandhi.pptx
ShrutiMahanta1
 
LEGAL ASPECTS OF PSYCHIATRUC NURSING.pptx
PoojaSen20
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
1, 2, 3… E MAIS UM CICLO CHEGA AO FIM!.pdf
Colégio Santa Teresinha
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Define Translation to Custom Module And Add a new language in Odoo 18
Celine George
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Ad

C Lang notes.ppt

  • 1. LANGUAGE A language is a communication media between two parties Programming languages: A programming language is a language used in writing programs to direct processing steps to be carried out by a computer.
  • 2. Programming languages are classified into 3 categories 1) Machine Language (or) Binary language 2. Assembly language 3) High level language
  • 3. Machine level Language  Machine code is the fundamental language of a computer and is normally written as strings of binary 1’s and 0’s. The circuitry of a computer is wired in such a way that it immediately recognizes the machine language and converts it into the electrical signals needed to run the computer.  Programs written in machine language can be executed very fast by the computer. This is mainly because the CPU directly understands machine instructions and no translation of the program is required.  Advantages:- If we know this language we can directly interact with the system, with out depending on any other applications.
  • 4. Assembly language The language, which substitutes letters and symbols for the numbers in the machine language program, is called an assembly language or symbolic language. The translator program that translates an assembly code into the computer’s machine code is called assembler. The assembler is a system program, which is supplied by the computer manufacturer. Advantages of Assembly language:  Easier to understand and use  Easy to locate and correct errors  Easier to modify  No worry about addresses  Easily re locatable.
  • 5. High level language  Every instruction, which the programmer writes in a high-level language, is translated into many machine language instructions.  While writing programs in any of the above languages, a programmer has to remember all the operation codes of the computer and now in detail what each code does and how it affects the various registers of the computers.  These languages enable the programmer to write instructions using English words and familiar mathematical symbols.
  • 6. Low level languages They are machine dependent languages. These are easily understood by computers. The machine language and assembly languages are examples of low level languages.
  • 7. Machine Languages As the name implies, programming is done at machine level. The vocabulary of computer consists of only two words zero and one. e.g., 10101011
  • 8. Assembly Language To overcome the drawbacks of the machine level language, computer engineers developed new programming language which uses symbolic instructions. This symbolic instruction oriented programming language is known as Assembly level language. E.g., ADD X,Y; Add the contents of y to x
  • 9. Compiler Interpreter 1. Compiler converts all statements at a time, if errors are there, it displays all errors as a list. 2. After Compiling the whole program, if the program is error free then it will execute the program. 3. After Compilation, it creates an executable file, using that executable file we can run the program any number of times. 4. It is fast. 1. Interpreter converts line by line, at the time of interpreting any error is there, it displays that error. 2. After interpreting the first line, if it is error free then it will execute that line. 3. It does not create any executable file, every time we need to interpret the program. 4. It is slow. Differences between Compiler and interpreter
  • 10.  Programming : The art of writing instructions for computer to solve the specific task is known as programming. The output of programming is a well defined set of instructions. This is called a program.  Algorithm A sequence of language independent which may be followed to solve a problem.  Flowchart Diagrammatic representation of step for solving the given problem
  • 11. Algorithm Calculating area of a circle 1. Start 2. Input radius in cm 3. Calculate, area=3.14*(radius*radius) 4. Display 5. Stop
  • 14. 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 a man named Dennies Ritche.
  • 15. Features of C  Portability and machine Independent.  Fast program execution.  An extendible language.  It is a structured programming language.
  • 16. Programming in C Character Set of C Program C Tokens 1. Alphabets 2. Numeric Digits 3. Special Characters 1. Constants 2. Variables 3. Keywords 4. Identifiers Instructions
  • 17. Character set of the C language This indicates group of characters which are useful to write the programming statements. It contains 3 parts.  Alphabets: C language supports upper case letters (A to Z), lower case letters from (a to z). But both are different. C is a case sensitive language.  Numeric digits: C language contains the numeric digits from 0 to 9.  Special Characters: The characters other than alphabets and numeric digits are called as special characters.
  • 18. Constants It is a quantity which does not change its value during executing a program. Types of C constants 1. primary constants 2. Secondary constants
  • 20. Integer constants Integer Constant: These are the numbers without decimal point or exponent. Ex:- int a=10; Real Constants Float constant: These are the numbers with decimal point or exponent. Ex:- float pie=3.14;
  • 21. Character Constants Single Character Constant: It is any one of the single character enclosed in single quotation. Ex:- char ch=’a’; char section=’b’; String constant: Group of characters enclosed with in double quotations. Ex:- char name[20]= “Chandra”; char nation[10]= “India”;
  • 22. Variables It is a name given to the memory location which holds a particular data value that can be change during the execution of the program. Variables are 4 types.  Integer variables  Float variables  Single character variables  String variables.
  • 23. Local & global variables 1. Local variable - A variable declared inside a function. This variable can only be used in the function. 2. Global variable - A variable declared outside of any functions. This variable can be used anywhere in the program.
  • 24. Rules to write variable names  It must not exceed 31 characters.  A variable name includes alphabets and numbers, but it must start with an alphabet.  It cannot accept any special characters, blank spaces except under score( _ ).  It should not be a reserved word.
  • 25. Identifiers Identifiers are names given to various program elements, such as variables, functions and arrays.
  • 26. key words(or) Reserved words Keywords are the words whose meaning has already been explained to the C compiler. The keywords cannot be used as variable names.
  • 28. Data types Data type Range Bytes Format signed char -128 to +127 1 %c unsigned char 0 to 255 1 %c short signed int -32,768 to +32,767 2 %d short unsigned int 0 to 65,535 2 %u long signed int -2147483648 to +2147483647 4 %ld long unsigned int 0 to 4294967295 4 %lu Float -3.4e38 to +3.4e38 4 %f Double -1.7e308 to +1.7e308 8 %lf long double -1.7e4932 to 1.7e4932 10 %lf
  • 29. Input and Output functions 1. Formatted I/O functions Input function – scanf() Output function – printf() 2. Unformatted I/O functions Input function – gets() Output function – puts()
  • 30. Formatted I/O functions Output Function printf( ): This function is used to display the information on the screen. It displays the variable values and the string values. This function belongs to stdio.h. Syntax: printf(“control_string” ,variable_list);
  • 31. Examples:- int a=10; printf(“The value of a is %d”,a); float pie=3.14; printf(“The value of pie is %f”,pie); char ch=‘A’; printf(“Ch = %c”, ch); char name[20]=“ORBIT” printf(“Name = %s”, name);
  • 32. Input function scanf( ):- It is an input function, that is used to accept the input from the keyboard(user) at the time of executing a program. This function belongs to stdio.h . Syntax: scanf(“control_string”, variable_list);
  • 33. Examples:- int a; scanf(“%d”, &a); float b; scanf(“%f”,&b); char ch; scanf(“%c”,&ch); char name[20]; scanf(“%s”,name);
  • 34. Unformatted I/O functions Output function puts() This function is used to execute only string values. Syntax:- puts(string_variable); Ex:- char name[20]=“ORBIT”; puts(name);
  • 35. Input function gets() This function is used to accept only string values. Syntax:- gets(string_variable); Ex:- char name[20]; gets(name);
  • 36. Writing C Programs  A programmer uses a text editor to create or modify files containing C code.  Code is also known as source code.  A file containing source code is called as source file.  After C source file has been created, the programmer has to invoke C compiler in order to execute (run) the program.
  • 37. Structure of a C program /* Comment line section */  Documentation optional # header file section  when we use predefined functions main( ) { Declaration part;  To declare the variables which are used in the program Initialization part;  To initialize i.e. giving values to the variables Execution part;  To execute as output }
  • 38. Comment Line Section In order to give documentation for a program comment line is includes. It is enclosed in between a /* */ because in the compilation process these lines are not includes. Comments are two types Single line comment - // ------------ Multi line comment - /* ----------- -----------*/
  • 39. Header file section ‘C’ program consists of predefined functions for that reason we should include the files in which they are defined. Which are saved with .h as extension.
  • 40. Ex:- # include <stdio.h> stdio.h stands for standard input output . header file # - It is used to tell the preprocessor to get the header file to included in the source code. Include - it is used to include header file specified in your source code.
  • 41.  When we write our programs, there are libraries of functions to help us so that we do not have to write the same code over and over.  Some of the functions are very complex and long. Libraries of functions make it easier and faster to write programs.  Using the functions will also make it easier to learn to write a program. stdio.h
  • 42. Main( )  The compilation and the running process is done with the help of Main( ). Every program must have a function called main. This is where program execution begins.  main() is placed in the source code file as the first function for readability.  The parentheses following the reserved word “main” indicate that it is a function.
  • 43. Declaration part This area is where we declare all the variables which are used in the program. Initialization part Here, we give values to the declared variables. Executable part The output is seen from the executable part. By using output functions.
  • 44. getch() It is a predefined function available in <conio.h> library which reads the character from the keyboard without printing on the monitor. getche() It is a predefined function available in <conio.h> library which reads the character from the keyboard with printing on the monitor. clrscr() It is a predefined function available in <conio.h> library which clears the previous contents of user screen window.
  • 45. Execution of C Program Steps to be followed in writing and running a C program.  Creation of Source Program Create a C program code in Turbo C Editor.  Compilation of the Program Press Alt + F9 for compilation.  Program Execution In Turbo C environment, the RUN option will do the compilation and execution of a program. Press Ctrl + F9 for execution of the program.
  • 46. Operators  Arithmetic operators  Relational operators  Logical operators  Assignment operators  Increment or decrement operators  Conditional operators  Sizeof Operator  Bitwise Operator
  • 47. Arithmetic Operators Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, division and remainder. Operator Name Meaning Example + Plus Addition a+b - Minus Subtraction a-b * Asterisk Multiplication a*b / Slash Division a/b % Modulator Reminder a%b
  • 48. Relational operators These operators are used to check the relation between the values. Note:- When we used relational operators the output is seen in the form of 0 or 1. If the relation is true the output will be in 1. If the relation is false the output will be 0. Ex:- a=10 b=5 Operator Example Result > a>b 1 < a<b 0 >= a>=b 1 <= a<=b 0 = = a==b 0 != a!=b 1
  • 49. Logical operators logical operators are used to combine two or more relational expressions. C language contains 3 logical operators. Operator Name && And || Or ! Not
  • 50. && : (And) Statement:- When all arguments are true then only the total condition is true. Any one of the arguments is false the total condition is false. Expressinn1 && Expression2 Result T T T T F F F T F F F F Truth table
  • 51. || : (Or) Statement:- When one of the argument is true the total condition is true. If all the arguments are false then only the condition is false. Expression1 || Expression2 Result T T T T F T F T T F F F Truth table
  • 52. ! (Not) Statement:- This is the negative operator, we can place the ‘not’ operator before any one of the condition. It returns the opposite result of the condition. i.e. It converts true to false and false to true. ! expression result T F F T Truth table
  • 53. Assignment operator C language contains equal to (=) operator to assign a value or expression into a variable. Ex:- a=10; b=a+10;
  • 54. Increment and decrement operators 1. Increment operator (+ +) Increment operator is used to increase the value by 1.  Pre Increment( ++a) First the value will be incremented, and then the new value will be executed. Ex:- printf(“%d”,++a);  Post Increment(a++) First the value will be executed and then one value will be incremented. Ex:- printf(“%d”,a++);
  • 55. 2) Decrement operator ( - - ) Decrement operator is used to decrease the value by 1.  Pre Decrement (--a) If the value is decreased before execution it is called as pre decrement. Ex:- printf(“%d”,--a);  Post Decrement (a--) If the value is decreased after the execution it is called as post decrement. Ex:- printf(“%d”,a--)
  • 56. Conditional operators C language contains conditional operators (?, : ). By using conditional operators we can get the output in the form of statements also. ? and : are called as conditional or ternary operators. Syn:- (condition) ? printf(“value 1”) : printf(“ value 2”); Ex:- (a>b) ? printf(“a greater than b”):printf(“a is less than b”); If the condition is true then value1 will be executed, if the condition is false then value2 will be executed.
  • 57. Size of Operator This operator is used to find memory size of the variable or datatype. Syntax:- sizeof(variable or datatype);
  • 58. Complement operator (~) It gives the ones complement of the number.  Add one to the given number  Change it's sign
  • 59. Bitwise operators Bitwise operators compares internal binary format of the number. These operators are applicable in between integer variables only.  Bitwise AND &  Bitwise OR |  Bitwise XOR ^  Bitwise Left shift <<  Bitwise Right shift >>
  • 60. A B & | ^ ---------------------------------------------- 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 ---------------------------------------------------- Ex:- int a=10,b=8,c; c=a&b; 10 : 1 0 1 0 8 : 1 0 0 0 --------------------------- c : 1 0 0 0 Answer=8
  • 61. c=a|b; 10 : 1 0 1 0 8 : 1 0 0 0 --------------------------- c : 1 0 1 0 Answer=10 c=a^b; 10 : 1 0 1 0 8 : 1 0 0 0 --------------------------- c : 0 0 1 0 Answer=2
  • 62. Bitwise Left shift operator (<<) Bitwise Left shift operator shifts the number of bits toward left side specified number of times and fills right side bit with zero. Or Multiply the given number by specified number of powers of 2. int a=10,b; b=a<<1; a*2=10*2=20 b=a<<2; a*2*2=10*2*2=40 b=a<<3; a*2*2*2=10*2*2*2=80
  • 63. Bitwise Right shift operator (>>) Bitwise right shift operator shifts the number of bits towards right side specified number of times and fills left side bits with zero. Or Divide the given number by specified number of of powers of 2. int a=10,b; b=a>>1; a/2=10/2=5 b=a>>2; a/(2*2)=10/(2*2)=2 b=a>>3; a/(2*2*2)=10/(2*2*2)=1
  • 64. PRECEDENCE OF OPERATORS (Arithmetic operators only) Operator Description Associativity * / % + - Multiplication Division Modulo Addition Subtraction Left to right “ “ “ “
  • 65. Conditional statements The statements which are executed according to some condition are called as conditional statements. They are 3 types  If  If-else  Nested if-else
  • 66. The If statement Statement: This statement is used to perform conditional operations. Syntax: if(condition) { statement; } If the condition is true then statement will be executed. If the condition is false then it will not execute statement.
  • 68. If-else The general form of if-else statement is… Syntax: if(condition) { statement1; } else { statement2; } If the condition is true then statement1 will be executed, if the condition is false then statement2 Will be executed.
  • 69. Flow chart Statement(s); Next statements(if any) Statement(s); if(condition) False True
  • 70. Nested if-else When a series of conditions are involved, we can use more than one if-else statement in nested form. Syntax: if (condition) { statements; } else if (condition) { statements; } else { statements; }
  • 71. Switch statement It is used to execute one of the options from no. of options. It is also called as multi branching statement. Switch (expression) { case value: statements; case value: statements; default: statements; } The expression value may be int or character type. The switch statement evaluates the expression. It will select one of the cases based on expression. It will execute default statements when no case is selected.
  • 72. Break statement  This control statement can be used in loops and switch statements.  It is used to terminate the loop when a specified condition is satisfied.  The control comes out of the loop and the following statements are executed.  In switch statements, the control comes out of the switch statements and the following statements are executed.
  • 73. Switch case Syntax: switch(expression) { case 1: { statement; } break; case 2: { statement; } break; default: { statement; } }
  • 74. Flow chart switch(expression) Case 1: Match ? Statement(s); break; case 2: Match ? Statement(s); break; case n: Match ? Statement(s); break; default Statement/s; Next statement
  • 75. The exit( ) Function  The exit( ) is a function in the standard library of C.  This function causes immediate termination of the program and execution control returns to the operating system.
  • 76. Control Statements Unconditional control statements:  goto statement  break statement  continue statement Looping/Repetitive/Iteration control statements:  for statement  while statement  do-while statement
  • 77. Goto statement Syntax: goto label; . . label : Statement(s); This is an unconditional control statement to tell the compiler from where the next statements has to be executed. In other words, program control directly Jumps to some location in a program with the help of this statement.
  • 78. Continue statement  This control statements are used in the loops.  During execution if a continue statement is encountered all the following statements will be terminated and the control will go to the next iteration of the loop without executing the following statements in the loop.
  • 79. Loop control structures LOOPING:- The process of executing a block of code repeatedly is called as looping. They are 4 types  For loop  While loop  Do while loop  Nested for loops
  • 80. All the four loops are used for same process but there syntax is different. All the four loops have 3 steps is common.  Initialization:- It is the starting point of the loop process.  Condition:- In this step logical test is applied. It is true the block of code is executed. Till the condition fails.  Increment / Decrement:- In order to proceed or stop the loop increment or decrement is required.
  • 81. For loop It is used to execute a set of statements repeatedly as long as the given condition is true. Syntax:- for (initial value ; test condition ; increment /decrement) { statements; //body of for loop } Ex:- for(i=1; i<=10; i++)
  • 82. For loop It is used to execute a set of statements repeatedly as long as the given condition is true. Syntax:- for (initial value ; test condition ; increment /decrement) { statements; //body of for loop } Ex:- for(i=1; i<=10; i++) Initialization expression Test expression Body of the loop Update expression Next statements (if any) False True Flow chart
  • 83. While loop It is used to execute a set of statements repeatedly as long as the given condition is true. Syntax:- while (condition) { statements; //body of while loop } First the condition is tested, if it is true the body of the while loop will be executed first time, again the control is transferred back to while loop and checks the condition, If it is false the control will come out of the while loop.
  • 85. Do While Loop This statement executes a set of statements as long as the condition is true. Syntax: do { statements; statements; } while(condition); This is similar to while loop, but the difference is this loop will execute the statements at least once.
  • 87. Nested for loop In order to get the output in the form of rows and columns we use nested for loops. If the outer loop condition is true it enters into the inner loop. Till the outer loop condition is false the looping process is continued.
  • 88. ARRAYS An array is contiguous area in the memory referred by a common name. The array allows the storage of a number of data values in one variable. Each array element i.e. each individual data item is referred by specifying the array name followed by one or more subscripts. Each subscript is enclosed with square brackets. Each subscript indicates the position of the element in the array. Arrays are divided into 2 types. 1. Single dimensional array or One dimensional array 2. Two dimensional array
  • 89. One dimensional array The array which is using only 1 subscript is known as one dimensional array. In one dimensional array the elements are represented in single row or single column. Syntax:- Data_type variable_name[subscript] Ex:- int a[5]={40, 50, 70,90,100}; Float b[4]={20.5, 40.9, 45.7, 23.8}; Char c[5]={‘O’,’R’,’B’,’I’,’T’};
  • 90. Multi dimensional array The array which is using two subscripts is known as 2 – dimensional array Syntax:- Data_type variable_name [subscript][subscript] Ex:- int a[2][2]={{1,2,},{3,4}}; The above declaration states that ‘a’ is an two dimensional Array variable in which the values are stored in 2 rows and in 2 columns
  • 91. String Functions A character array is defined as a string. A group of characters is called a string. We cannot handle with string same like integers or real values. For example, if you want to compare an integer value with another int value. We can do that by using = = operator. But the same procedure cannot be applied for strings. In order to handle with strings there are some string handling functions.
  • 92. Strlen( ) This function is used to find the length of a string. Syntax:- strlen(string); Note:- When we are using string functions we have to include a header file <string.h>
  • 93. Strcpy( ) This function copies a string from one string variable to another string variable. Syntax:- strcpy(target_string , source_string);
  • 94. Strcat( ):- (String concatenation) This function adds a string at the end of another string Syntax:- strcat(string1,stirng2);
  • 95. Strcmp( ):- (String comparison) This compares one string with another string. Syntax:- strcmp(string1, string2);
  • 96. Stricmp( ) This function is similar to strcmp, but this function ignores the case sensitivity. Syntax:- stricmp(string1, string2);
  • 97. Strrev( ) This function reverses the given string. Syntax:- strrev(string);
  • 98. Strupr( ) This function converts the given string into upper case (capital letters) Syntax:- strupr(string);
  • 99. Strlwr( ) This function converts the given string into lower case. Syntax:- strlwr(string);
  • 100. Single character 1) toupper( ) :- This function converts a single character to upper case. Syntax:- toupper(character); 2) tolower( ) :- This function converts a single character to lower case. Syntax:- tolower(character);  Note:- when we are using single character functions we have to include a header file <ctype.h>
  • 101. Functions A function is a set of statements that performs a specific task. Functions are 2 types 1. Pre defined functions or Standard functions 2. User defined functions
  • 102. Pre defined Functions These functions which are already defined (in built) along with C are called as pre defined functions. Ex:- printf( ), scanf( ), pow( ), strlen( ), strcpy( ), toupper( ),……
  • 103. User defined functions These functions defined by the user in order to work with complex program and to develop the efficiency of the program are called as user defined functions. In order to define a function we have 3 types. • Function definition • Function prototype • Invoking a function
  • 104. Function definition  Function heading • Return type • Function name • Specification of parameters
  • 105. a. Return type:- Return is called as data type mention according to the type of value returned from the function. Note:- When there is no return statement we should mention void as a default return type. b. Function name:- Here we mention the name of a function. It is just like a variable name
  • 106. C. Specification of parameters:- The specify the number of values are variables taken by the called function from main program. Note:-The parameters mentioned in the main program for calling a function are called as actual parameters. The parameters mentioned in the function which are received from the main program are called formal parameters.
  • 107.  Block of code The code which is written with in the braces of a function is called as block of code.  Return statement This is the last statement of a function it is to return a value from the user defined function to the main program.
  • 108. It is declared in the main program about the function. Note:- Function prototype is optional if the function is defined before the main. It is compulsory if the function is defined after the main. Function Prototype
  • 109. Invoking a Function From here we call the function. A function as no live when it is not Invoked.
  • 110. Uses of functions  Dividing the task into sub tasks.  If a particular task is repeated number of times in a program we can create a function and call that function wherever we want.  Whenever a function is called in a statement the control will be transferred to that called function. After executing all statements it returns back to the calling function.  The length of the source program will be reduced by using functions at appropriate places.  A function can be used in other programs also.
  • 111. Syntax of a function / function definition Return_type function_name (argument list) { declarations; statements; ------------- return value; } Function declaration Return_type function_name (argument list);
  • 113. Pointers Pointer is a memory location or a variable which stores the memory address of another variable in memory Pointers are much more commonly used in C & C++ than in many other languages (such as BASIC, Pascal, and certainly Java, which has no pointers).
  • 114. Problem solving using C++ What are pointers for? Here are some common uses: • Accessing array elements • Passing arguments to a function when the function needs to modify the original argument • Passing arrays and strings to functions • Obtaining memory from the system • Creating data structures such as linked lists
  • 115. Memory map i 65524 ‘i’ - Location name 10 - Value at location 65524 – Location number or address. Declaration of a pointer: Int a, *x; Float b, *y; Char c, *z; Pointer variable is same as normal variable. But a * symbol is added before the variable. 10
  • 116. Usage of pointers As pointers work with addresses accessing through addresses first then through a normal variable. When the values are called with the help of address by a function the modifications done to the variables shows the reflection. Indirectly we can get the value of a variable by using *. So * is called as indirection operator. Whatever the data type may be a pointer variable occupies only 2 bytes of memory.
  • 117. Parameter passing mechanism  Call by value  Call by address  Call by value:- When the function calls the parameters by taking values the modifications done to the parameters by the function doesn’t reflect.  Call by address:- When the parameters are called by address the changes done to the values within the function shows the reflection.
  • 118. Structures Structure is a user defined data type. A structure is a collection of variables that is referenced under a single name. A structure contains a number of data types grouped together. These data types may or may not be of the same type. Definition of a structure: - Structure is a collection of variables which are of dissimilar data types.
  • 119. Declaring a structure:- struct <structure name> { structure element 1; structure element 2; --- structure element n; }; structure variable;
  • 120. Ex:- struct book { int pages; char author[20]; float price; };  In the above declaration book is called Tag name and pages, author, price are called as data members of the structure
  • 121. Declaring a variable for a structure Ex:- struct book b; Here, ‘b’ is a variable of a structure to which we can give 3 details. The data members of the structure are called by the variable using ( . ) operator. For example:- b.pages b.author b.price
  • 122. Features of a structure With the help of structure we can maintain a data in a systematic order. We can handle a structure within a structure. And also we can call the structure variable through functions and Arrays also can be implemented through structures. Pointer to structure is also possible.
  • 123. Unions A union is similar to structure, but the difference is 1. The size of the structure variable is sum of all the members size, but union size is the maximum member's size. 2. In structure we can see all members at a time, but in union we can see only one member at a time because when we store the second member, first value will be over written.
  • 124. Files File is a collection of data to be stored permanently in the disk space. The disk may be either hard disk or floppy disk or compact disk
  • 125. Difference between Array and File 1.File is a collection of data. The data may be of similar or dissimilar type. Array is collection of elements of similar datatype. 2. File size is unlimited. Array size is limited. 3.File data is stored permanently in the disk space. Array data is stored temporarily in the RAM.
  • 126. To Create a File pointer FILE is a macro which is used to create a file pointer which holds the address of some file. Syntax:- FILE * file_pointer; Example:- FILE *fp;
  • 127. To create or open the file fopen() It is a predefined function available in <stdio.h> which is used to create or open the file. Syntax:- file_pointer=fopen(filename,"Modes");
  • 128. Modes are nothing but permissions to create or open the file.There are 6 modes. r:- fp=fopen(“Filename.extn","r"); If the file is already exist then it opens the file with read permission. r+ :- fp=fopen(“Filename.extn","r+"); If the file is already exist then it opens the file with read and write permission.
  • 129. W :- fp=fopen(“Filename.extn","w"); If the file is already exist then it opens the file with write permission by deleting previous data else creates the new file. w+ :- fp=fopen(“Filename.extn","w+"); If the file is already exist then it opens the file with read and write permission else creates the new file.
  • 130. a :- fp=fopen(“Filename.extn","a"); If the file is already exist then it opens the file with add permission else creates the new file. a+ :- fp=fopen(“Filename.extn","a+"); It creats or opens the file with read write and append permission.
  • 131. To close the file fclose() It is a predefined function available in <stdio.h> which is used to close the specified file. Syntax fclose(file_pointer); Example fclose(fp);
  • 132. getchar() getchar() is a macro that gets a character from stdin Syntax: - int getchar(void); putchar() putchar() is a macro that outputs a character on stdout Syntax: -int putchar(int c);
  • 133. getc() getc() is a macro that gets one character from a stream Syntax: - getc(file_pointer); putc() putc() is a macro that outputs a character to a stream Syntax: - putc(character, file_pointer);
  • 134. fputs() fputs copies the null-terminated string s to the given output stream. It does not append a newline character, and the terminating null character is not copied. Syntax: - fputs(character, file_pointer); fgets() fgets reads characters from stream into the string. It stops when it reads either n - 1 characters or a newline character, whichever comes first. Syntax: - fgets(character, file_pointer);
  • 135. To write the character into the file fputc() It is a predefined function available in <stdio.h> which is used to write the specified character into the file. Syntax fputc(charactervariable,file_pointer); Example char ch='A'; fputc(ch,fp);
  • 136. To read the character from the file fgetc() It is a predefined function available in <stdio.h> which is used to read the character from file. Syntax charactervariable=fgetc(file_pointer); Example char ch; ch=fgetc(fp);
  • 137. To delete the file remove() It is a predefined function available in <stdio.h> which is used to remove the specified file. Syntax remove(filename); Example remove("Sachin");
  • 138. To rename the file rename() It is a predefined function available in <stdio.h> which is used to rename the file. Syntax rename(old filename,new file name); Example rename("Sachin","Mahesh");
  • 139. To write the different types of data into the file fprintf() It is a predefined function available in <stdio.h> which is used to write the different types of data into the file . Syntax fprintf(file_pointer,"formatspecifier",variable); Example char c='@'; int i=10; float f=34.56 fprintf(fp,"%d%c%f",i,c,f);
  • 140. To read the different types of data from the file fscanf() It is a predefined function available in <stdio.h> which is used to read the different types of data from the file . Syntax fscanf(file_pointer,"formatspecifier",Address of variable); Example char c; int i; float f; fscanf(fp,"%d%c%f",&i,&c,&f);
  • 141. storage classes They are 4 types 1) automatic storage class 2) register storage class 3) static storage class 4) external storage class
  • 142. Automatic storage class The features of a variable defined to have an automatic storage class are as under  Storage : Memory  Default initial value : Garbage value  Scope : Local to block in which the variable is defined  Life : Till the control within the block in which the variable is defined
  • 143. Register storage class  Storage : CPU registers  Default initial value : Garbage value  Scope : Local to block in which the variable is defined  Life : Till the control within the block in which the variable is defined
  • 144. Static storage class  Storage : Memory  Default initial value : Zero  Scope : Local to block in which the variable is defined  Life : Value of the persists between different function calls
  • 145. External storage class  Storage : Memory  Default initial value : Zero  Scope : Global  Life : As long as the program execution doesn't come to an end