SlideShare a Scribd company logo
1 of 60
 Sachin Dane
C language is a general purpose and structured programming
language developed by 'Dennis Ritchie' at AT &T's Bell
Laboratories in the 1972s in USA.
 It is also called as 'Procedure oriented programming
language.'
 C is not specially designed for specific applications areas
like COBOL (Common Business-Oriented Language) or
FORTRAN (Formula Translation).
 It is well suited for business and scientific applications.
 It has some various features like control structures,
looping statements, arrays, macros required for these
applications.
 The C language has following numerous features as:
 Portability
 Flexibility
 Effectiveness and efficiency
 Reliability
 Interactivity
Execution of C Program :
C program executes in following 4 (four steps).
1.Creating a program :
An editor like notepad or WordPad is used to create a C program.
This file contains a source code which consists of executable code.
The file should be saved as '*.c' extension only.
2.Compiling the program :
The next step is to compile the program. The code is compiled by using
compiler.
Compiler converts executable code to binary code i.e. object code.
3.Linking a program to library :
The object code of a program is linked with libraries that are needed for
execution of a program.
The linker is used to link the program with libraries.
It creates a file with '*.exe' extension.
4.Execution of program :
The final executable file is then run by dos command prompt or by any
other software.
Year of Establishment Language Name Developed By
1960 ALGOL-60 Cambridge University
1963
CPL (Combined
Programming
Language)
Cambridge University
1967
BCPL (Basic Combined
Programming
Language)
Martin Richard at
Cambridge University
1970 B
Ken Thompson at AT &
T's Bell Laboratories.
1972 C
Dennis Ritchie at AT &
T' Bell Laboratory.
Document Section
Links Section (File)
Definition Section
Global variable declaration Section
void main()
{
Variable declaration section
Function declaration section
executable statements;
}
Function definition 1
---------------------
---------------------
Function definition n
where,
where,
 Document Section : It consists of set of comment lines which include name
of a program, author name, creation date and other information.
 Links Section (File) : It is used to link the required system libraries or
header files to excute a program.
 Definition Section : It is used to define or set values to variables.
 Global variable declaration Section : It is used to declare global or public
variable.
 void main() : Used to start of actual C program. It includes two parts as
declaration part and executable part.
 Variable declaration section : Used to declare private variable.
 Then, executable statements are placed for execution.
 Function definition section : Used to define functions which are to be
called from main().
VARIABLES AND KEYWORDS
 Character Set :
A character refers to the digit, alphabet or special symbol used to data
representation.
1. Alphabets : A-Z, a-z
2. Digits : 0-9
3. Special Characters : ~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ?  | : ; " '
4. White Spaces : Horizontal tab, Carriage return, New line
 Identifier :
identifier is the name of a variable that is made up from combination of
alphabets, digits and underscore.
 Variable :
It is a data name which is used to store data and may change during program
execution. It is opposite to constant. Variable name is a name given to
memory cells location of a computer where data is stored.
* Rules for variables:
• First character should be letter or alphabet.
• Keywords are not allowed to use as a variable name.
• White space is not allowed.
• C is case sensitive i.e. UPPER and lower case are significant.
• Only underscore, special symbol is allowed between two characters.
int float double long
short signed unsigned const
if else switch break
default do while for
register extern static struct
typedef enum return sizeof
goto union auto case
void char continue volatile
Keywords :
 Keywords are the system defined identifiers.
 All keywords have fixed meanings that do not change.
 White spaces are not allowed in keywords.
 Keyword may not be used as an identifier.
 It is strongly recommended that keywords should be in lower case
letters.
There are totally 32(Thirty Two) keywords used in a C programming.
Escape Sequence Characters (Backslash Character Constants) in C:
C supports some special escape sequence characters that are used to do special tasks.
Character Constant Meaning
n New line (Line break)
b Backspace
t Horizontal Tab
f Form feed
a Alert (alerts a bell)
r Carriage Return
v Vertical Tab
? Question Mark
' Single Quote
'' Double Quote
 Backslash
0 Null
Constants in C
A constant is an entity that doesn't change during the execution of a
program.
Syntax: const data type var_name=expression;
Ex: const float pi=3.147
Followings are the different types of constants :
1. Real Constant :
It must have a decimal point which may be positive or negative.
Example:
+194.143, -416.41
2. Integer Constant :
It should not contain a decimal place.
It can be positive or negative.
Example:
1990, 194, -394
3. Character Constant :
It is a single alphabet or a digit or a special symbol enclosed in a single quote.
Maximum length of a character constant is 1.
Example:
'T', '9', '$'
4. String Constant :
It may contain letters, digits, special characters and blank space.
Example:
“Hello friends welcome"
Data Types in C :
"Data type can be defined as the type of data of variable or constant store."
Keyword Format Specifier Size Data Range
char %c 1 Byte -128 to +127
unsigned char <-- -- > 8 Bytes 0 to 255
int %d 2 Bytes -32768 to +32767
long int %ld 4 Bytes -231 to +231
unsigned int %u 2 Bytes 0 to 65535
float %f 4 Bytes -3.4e38 to +3.4e38
double %lf 8 Bytes -1.7e38 to +1.7e38
long double %Lf 12-16 Bytes -3.4e38 to +3.4e38
Followings are the most commonly used data types in C.
Operator Name Operators
Assignment =
Arithmetic + , - , *, /, %
Logical &&, ||, !
Relational <, >, <=, >=, ==, !=
Shorthand +=, -=, *=, /=, %=
Unary ++, --
Conditional Y=(x>9)? 100 :200 ;
Bitwise &, |, ^, <<, >>, ~
Operators in C :
"Operator is a symbol that is used to perform operations.“
 Followings are the most commonly used data types in C.
Conditional Operator (?:)
The conditional operator ?: is a ternary operator. This means that it takes in
three
arguments that together form a conditional expression.
Syntax:
exp1?exp2:exp3
Where in exp1 is a boolean expression whose result must either be true or false.
If exp1 is true, exp2 is the value returned. If it is false, then exp3 is returned.
For example, given the code,
public class ConditionalOperator
{
public static void main( String[] args ){
String status = "";
int grade = 80;
//get status of the student
status = (grade >= 60)?"Passed":"Fail";
//print status
System.out.println( status );
}
}
The output of this program will be,
Passed
Here is the flowchart of how ?: works,
Increment and Decrement operators
Java includes a unary increment operator (++) and decrement operator (--).
Increment and decrement operators increase and decrease a value stored in a
number variable by 1.
For example, the expression,
count = count + 1; //increment the value of count by 1
is equivalent to,
count++;
Operator Use Description
++ op++ Increments op by 1; evaluates to
the value of op before it was incremented
++ ++op Increments op by 1;evaluates to
the value of op after it was incremented
-- op-- Decrements op by 1;evaluates to
the value of op before it was decremented
-- --op Decrements op by 1;evaluates to
the value of op after it was decremented
For example,
int i = 10,
int j = 3;
int k = 0;
k = ++j + i; //will result to k = 4+10 = 14
k = j++ + i; //will result to k = 3+10 = 13
Input output statements in C
printf(“ msg ”);
Scanf(“format specifier ”,&var_name );
printf(“format specifier”,var_name);
 printf(“msg format specifier”,var_name);
Decision Making Statements / Conditional Statements :
C program executes program sequentially. Sometimes, a program requires
checking of certain conditions in program execution.
 Followings are the different conditional statements used in C.
 If Statement
 If-Else Statement
 Nested If-Else Statement
 Switch Case
If Statement :
This is a conditional statement used in C to check condition or to
control the flow of execution of statements.
Syntax: if (condition)
{
statements;
}
In above syntax, the condition is checked first. If it is true, then
the program control flow goes inside the braces and executes the
block of statements associated with it. If it returns false, then
program skips the braces.
If-Else Statement :
This is also one of the most useful conditional statement used in C to
check conditions.
Syntax:
if(condition)
{
true statements;
}
else
{
false statements;
}
In above syntax, the condition is checked first. If it is true, then
the program control flow goes inside the braces and executes the
block of statements associated with it. If it returns false, then it
executes the else part of a program.
Nested If-Else Statement :
It is a conditional statement which is used when we want to check more than 1
conditions at a time in a same program. The conditions are executed from top to
bottom checking each condition whether it meets the conditional criteria or not.
Syntax: if(condition)
{
if(condition)
{
statements;
}
else
{
statements;
}
}
else
{
statements;
}
In above syntax, the condition is checked first. If it is true, then the program
control flow goes inside the braces and again checks the next condition. If it is
true then it executes the block of statements associated with it else executes
else part.
Switch case Statement :
This is a multiple or multiway branching decision making statement.
When we use nested if-else statement to check more than 1 conditions then the
complexity of a program increases in case of a lot of conditions. So to overcome
this problem, C provides 'switch case'.
Switch case checks the value of a expression against a case values, if condition
matches the case values then the control is transferred to that point.
In this syntax,
switch, case,
break are
keywords.
expr1, expr2 are
known as 'case
labels.'
Break statement
causes an exit
from switch
statement.
Default case is
optional case.
When neither any
match found, it
executes
Syntax: switch(expression)
{
case expr1:
statements;
break;
case expr2:
statements;
break;
.
.
case expr N:
statements;
break;
default:
Statements;
break;
}
Looping Statements / Iterative Statements :
'A loop' is a part of code of a program which is executed
repeatedly.
A loop is used using condition. The repetition is done until
condition becomes condition true.
A loop declaration and execution can be done in following ways.
 Check condition to start a loop
 Initialize loop with declaring a variable.
 Executing statements inside loop.
 Increment or decrement of value of a variable.
* Types of looping statements :
Basically, the types of looping statements depends on the
condition checking mode.
Condition checking can be made in two ways as :
Before loop and after loop.
1. Entry controlled loop :
In such type of loop, the test condition is checked
first before the loop is executed.
Some common examples of this looping statements
are :
 while loop
 for loop
2. Exit controlled loop :
In such type of loop, the loop is executed first. Then
condition is checked after block of statements are
executed.
The loop executed atleast one time compulsorily.
Some common example of this looping statement is :
 do-while loop
So, there are 2(two) types of looping statements.
 Entry controlled loop
 Exit controlled loop
While loop :
This is an entry controlled looping statement. It is used to
repeat a block of statements until condition becomes true.
Syntax:
while(condition)
{
statements;
increment/decrement;
}
In above syntax, the condition is checked first. If it is true,
then the program control flow goes inside the loop and
executes the block of statements associated with it. At the
end of loop increment or decrement is done to change in
variable value. This process continues until test condition
satisfies.
Do-While loop :
This is an exit controlled looping statement.
Sometimes, there is need to execute a block of statements first
then to check condition. At that time such type of a loop is used.
In this, block of statements are executed first and then
condition is checked.
Syntax:
do
{
statements;
(increment/decrement);
}
while(condition);
In above syntax, the first the block of statements are executed.
At the end of loop, while statement is executed. If the resultant
condition is true then program control goes to evaluate the body
of a loop once again. This process continues till condition becomes
true. When it becomes false, then the loop terminates.
For loop :
This is an entry controlled looping statement.
In this loop structure, more than one variable can be initialized.
One of the most important feature of this loop is that the three
actions can be taken at a time like variable initialization, condition
checking and increment/decrement.
Syntax:
for(initialization; test-condition; incre/decre)
{
statements;
}
Features :
 More concise
 Easy to use
 Highly flexible
 More than one variable can be initialized.
 More than one increments can be applied.
 More than two conditions can be used.
 Break Statement :
Sometimes, it is necessary to exit immediately from a loop as soon as the
condition is satisfied.
When break statement is used inside a loop, then it can cause to terminate from
a loop. The statements after break statement are skipped.
 Continue Statement :
Sometimes, it is required to skip a part of a body of loop under specific
conditions. So, C supports 'continue' statement to overcome this problem.
The working structure of 'continue' is similar as that of that break statement
but difference is that it cannot terminate the loop. Continue statement simply
skips statements and continues next iteration.
Syntax : break;
While(condition)
{
- - - - -
- - - - - -
break;
- - -
- - -
}
Syntax : continue;
While(condition)
{
- - - - -
- - - - - -
Continue;
- - - -
- - - -
}
Goto Statement :
It is a well known as 'jumping statement.' It is primarily used to transfer
the control of execution to any place in a program. It is useful to provide
branching within a loop.
When the loops are deeply nested at that if an error occurs then it is
difficult to get exited from such loops. Simple break statement cannot work
here properly. In this situations, goto statement is used.
Syntax : goto [expr];
While(condition)
{
- - - - -
- - - - - -
goto label;
- - -
- - -
label:
}
While(condition)
{
- - - - -
label:
- - - -
- - - -
goto label;
- - -
}
Functions in C :
The function is a self contained block of statements which performs a coherent
task of a same kind.
Types of functions :
• Built in Functions
• User Defined Functions
1. Built in Functions : These functions are also called as 'library
functions'. These functions are provided by system. These functions are
stored in library files.
e.g.
scanf()
printf()
strcpy()
strlwr()
strcmp()
strlen()
strcat()
2.User Defined Functions :
The functions which are created by user for program are known as
'User defined functions'.
Advantages :
 It is easy to use, It reduces the size of a program.
 Debugging is more suitable for programs.
 It is easy to understand the actual logic of a program.
 Highly suited in case of large programs.
 By using functions in a program, it is possible to construct
modular and structured programs.
Syntax:
// Function definition
<return_type> <function_name>(argu_list);
void main()
{
// Function Call
<function_name>(<arguments>);
}
// Function declaration
<return_type><function_name>(<argu_list>)
{
<function_body>;
}
FUNCTION TYPES:
1) Function with No arguments and No return value
2) Function with arguments but No return value
3) Function with No arguments but Returns a value
4) Function with arguments and return values
5) Function with multiple return values
In this ex. a & b are
actual arguments & x is
formal argument
 Some Points about functions:
 A function cannot be defined within another function.
 All function definitions must be disjoint.
 Nested function calls are allowed.
A calls B, B calls C, C calls D, etc.
The function called last will be the first to return.
 A function can also call itself, either directly or in a cycle.
A calls B, B calls C, C calls back A.
Called recursive call or recursion.
 Calling Functions :Call by value and call by reference
Used when invoking functions
 Call by Value:
 Copy of argument pass to a function
 Changes in function do not effect
original
 Call by reference:
 Passes original arguments to a function
 Changes in function effect original
Recursion
•A process by which a function calls itself repeatedly.
–Either directly.
•X calls X.
–Or cyclically in a chain.
•X calls Y, and Y calls X.
•Used for repetitive computations in which each action is stated in
terms of a previous result.
fact(n) = n * fact (n-1)
For a problem to be written in recursive form, two conditions are
to be satisfied:
–It should be possible to express the problem in
recursive form.
–The problem statement must include a stopping
condition
fact(n) = 1, if n = 0
= n * fact(n-1), if n > 0
 More example on recursion:
–GCD:
gcd(m, m) = m
Gcd(m, n) = gcd(m-n, n), if m > n
gcd(m, n) = gcd(n, n-m), if m < n
–Fibonacci series (1,1,2,3,5,8,13,21,….)
fib (0) = 1
fib (1) = 1
fib (n) = fib (n-1) + fib (n-2), if n > 1
 Mechanism of Execution:
-When a recursive program is executed, the recursive
function calls are not executed immediately.
–They are kept aside (on a stack) until the stopping
condition is encountered.
–The function calls are then executed in reverse order.
 Storage Class :
'Storage' refers to the scope of a variable and memory allocated
by compiler to store that variable. Scope of a variable is the
boundary within which a variable can be used. Storage class defines
the the scope and lifetime of a variable.
 Functions of storage class :
 To determine the location of a variable where it is stored ?
 Set initial value of a variable or if not specified then setting it
to default value.
 Defining scope of a variable.
 To determine the life of a variable.
 Types of Storage Classes :
Storage classes are categorized in 4 (four) types as,
1. Automatic storage class
2. Register storage class
3. Static storage class
4. External storage class
 Automatic Storage Class :
 Keyword : auto
 Storage Location : Main memory
 Initial Value : Garbage Value
 Life : Control remains in a block where it is defined.
 Scope : Local to the block in which variable is declared.
Syntax : auto [data_type] [variable_name];
Example : auto int a;
 Register Storage Class :
 Keyword : register
 Storage Location : CPU Register
 Initial Value : Garbage
 Life : Local to the block in which variable is
declared.
 Scope : Local to the block.
Syntax : register [data_type] [variable_name];
Example : register int a;
 Static Storage Class :
 Keyword : static
 Storage Location : Main memory
 Initial Value : Zero and can be initialize once only.
 Life : depends on function calls and the whole application or program.
 Scope : Local to the block.
Syntax : static [data_type] [variable_name];
Example : static int a;
 External Storage Class :
 Keyword : extern
 Storage Location : Main memory
 Initial Value : Zero
 Life : Until the program ends.
 Scope : Global to the program.
Syntax : extern [data_type] [variable_name];
Example : extern int a;
 Array :
Array is a fixed sized sequenced collection of the elements of the same
data type .‘
 Types of an Array :
1) Single / One Dimensional Array
2) Two Dimensional Array
 Single / One Dimensional Array :
The array which is used to represent and store data in a linear form is
called as 'single or one dimensional array.‘
Syntax: <data-type> <array_name> [size];
 Memory Allocation:
A[0] A[1] A[2] A[n]
5 7 2 12
1000 1002 1004 n
A[i]
element
address
 Two Dimensional Array :
The array which is used to represent and store data in a tabular form is
called as 'two dimensional array.' Such type of array specially used to
represent data in a matrix form.
The following syntax is used to represent two dimensional array.
Syntax: <data-type> <array_name> [row_size][column_size];
Example: int a[3][3];
It is also called as 'multidimensional array.'
a[0][0] a[0][1] a[0][2]
a[1][0] a[1][1] a[1][2]
a[2][0] a[2][1] a[2][2]
i row
j a[i][j]
Memory allocation for two dimensional array
 Limitations of two dimensional array :
 We cannot delete any element from an array.
 If we don't know that how many elements have to be stored in a memory
in advance, then there will be memory wastage if large array size is
specified.
“Structure “
Structure is user defined data type which is used to store heterogeneous
data under unique name. Keyword 'struct' is used to declare structure.
The variables which are declared inside the structure are called as
'members of structure'.
Syntax:
struct structure_nm
{
<data-type> element 1;
<data-type> element 2;
- - - - - - - - - - - -
- - - - - - - - -
<data-type> element n;
}struct_var;
* Accessing Structure Members :
Structure members can be accessed using member operator '.' .
It is also called as 'dot operator' or 'period operator'.
structure_var.member;
Structures within Structures (Nested Structures) :
Structures can be used as structures within structures. It is
also called as 'nesting of structures'.
Syntax:
struct structure_nm
{
<data-type> element 1;
<data-type> element 2;
- - - - - - - - - - - - -
- - - - - - - -
<data-type> element n;
struct structure_nm {
<data-type> element 1;
<data-type> element 2;
- - - - - - - - - - - -
- - - - - - - - - -
<data-type> element n;
}inner_struct_var;
}outer_struct_var;
Union
Union is user defined data type used to stored data under unique variable
name at single memory location.
Syntax of union is similar to structure. But the major difference
between structure and union is 'storage.' In structures, each member
has its own storage location, whereas all the members of union use the
same location. Union contains many members of different types, it can
handle only one member at a time.
Syntax:
union union_name
{
<data-type> element 1;
<data-type> element 2;
<data-type> element 3;
}union_variable;
Example:
union techno
{
int comp_id;
char nm;
float sal;
}tch; Memory Allocation
To access union members, we
can use the following syntax.
tch.comp_id
tch.nm
tch.sal
POINTER
Pointer is a variable which holds the memory address of another
variable. Pointers are represented by '*'. It is a derive data type in
C. Pointer returns the value of stored address.
Syntax: <data_type> *pointer_name;
int *tot;
int tot = 95;
In above syntax,
* = variable pointer_name is a pointer variable.
pointer_name requires memory location
pointer_name points to a variable of type data type.
 Features of Pointer :
* Pointer variable should have prefix '*'.
* Combination of data types is not allowed.
* Pointers are more effective and useful in handling arrays.
* It can also be used to return multiple values from a function using
function arguments.
* It supports dynamic memory management.
* It reduces complexity and length of a program.
* It helps to improve execution speed that results in reducing program
execution time.
String :
A string is a collection of characters. Strings are always
enlosed in double quotes as "string_constant".
Strings are used in string handling operations such as,
•Counting the length of a string.
•Comparing two strings.
•Copying one string to another.
•Converting lower case string to upper case.
•Converting upper case string to lower case.
•Joining two strings.
•Reversing string.
Declaration
Syntax: char string_nm[size];
Example: char name[50];
String Handling in C
Read Strings :
To read a string, we can use scanf() function with format specifier %s.
char name[50];
scanf("%s",name);
Write Strings :
To write a string, we can use printf() function with format specifier %s.
char name[50]; scanf("%s",name);
printf("%s",name);
String Structure :
When compiler assigns string to character array then it automatically
supplies null character ('0') at the end of string.
Thus, size of string = original length of string + 1.
char name[7]; name = "TECHNO"
Function Name Description
n=strlen (s1) Returns the length of a string.
strlwr (s1) Returns upper case letter to lower case.
strupr (s1) Returns lower case letter to upper case.
strcat (s1,s2) Concatenates two string.
strcmp (s1,s2) Compares two strings.
strrev (s1) Returns length of a string.
strcpy (s1,s2) Copies a string from source to destination.
String handling functions:
File handling in C
In C we use FILE * to represent a pointer to a file.
•fopen is used to open a file. It returns the special value NULL to indicate
that it couldn't open the file.
FILE *fptr;
char filename[]= "file2.dat";
fptr= fopen(filename,"w");
if (fptr== NULL)
{
printf(“ERROR IN FILE
CREATION”);
/* DO SOMETHING */
}
 Modes for opening files
•The second argument of fopen is the mode in which we
open the file.
•"r"opens a file for reading
•"w"creates a file for writing -and writes over all previous
contents (deletes the file so be careful!)
•"a"opens a file for appending -writing on the end of the
file
•“rb”read binary file (raw bytes)
•“wb”write binary file
 The exit() function
•Sometimes error checking means we want an
"emergency exit" from a program. We want it to stop
dead.
•In main we can use "return" to stop.
•In functions we can use exit to do this.
•Exit is part of the stdlib.h library exit(-1);
in a function is exactly the same as
return -1;
in the main routine
Writing to a file using fprintf( ):
fprintf( ) works just like printf and sprintf except that
its first argument is a file pointer.
FILE *fptr;
fptr= fopen("file.dat","w");
/* Check it's open */
fprintf(fptr,"Hello World!n");
FILE *fptr;
fptr= fopen("file.dat","w");
/* Check it's open */
fprintf(fptr,"Hello World!n");
 Reading Data Using fscanf( )
•We also read data from a file using fscanf( ).
FILE *fptr;
fptr= fopen(“input.dat”,“r”);
/* Check it's open */
if (fptr==NULL)
{
printf(“Error in opening file n”);
}
fscanf(fptr,“%d%d”,&x,&y);
20 30
input.dat
x=20
y=30
 Reading lines from a file using fgets( )
We can read a string using fgets( ).
fgets( ) takes 3 arguments, a string, a maximum
number of characters to read and a file pointer.
It returns NULL if there is an error.
FILE *fptr;
char line [1000];
/* Open file and check it is open */
while (fgets(line,1000,fptr)!= NULL)
{
printf("Read line %sn",line);
}
Closing a file
•We can close a file simply using fclose( )and the file pointer.
FILE *fptr;
char filename[]= "myfile.dat";
fptr= fopen(filename,"w");
if (fptr== NULL)
{
printf("Cannot open file to write!n");
exit(-1);
}
fprintf(fptr,"Hello World of filing!n");
fclose(fptr);
Opening
Closing
Access
Three special streams
Three special file streams are defined in the <stdio.h> header
•stdin reads input from the keyboard
•stdout send output to the screen
•stderr prints errors to an error device (usually also the
screen)
Ex:
fprintf(stdout,"Hello World!n");
Input File & Output File redirection
•One may redirect the input and output files to other files
(other than stdinand stdout).
•Usage: Suppose the executable file is a.out
$./a.out <in.dat>out.dat
in.dat
15 Give value of i Value of i=15
out.dat
No error: But an example to show error
message
Display screen
 Reading and Writing a character
•A character reading/writing is equivalent to reading/writing a byte.
intgetchar( );
intfgetc(FILE *fp);
intputchar(int c);
intfputc(intc, FILE *fp);
 Program use of getchar() and putchar():
#include<stdio.h>
main()
{ int c;
printf("Type text and press return to see it again n");
printf("For exiting press <CTRL D> n");
while((c=getchar( ))!=EOF)
putchar(c);
}
 Example:
char c;
c=getchar( );
putchar(c);
 Command Line Arguments:
Command line arguments may be passed by specifying them under main( ).
int main(int argc, char *argv[ ]);
Argument
count Array of Strings as
command line
arguments including the
command itself.
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])
{
FILE *ifp,*ofp;
int i,c;
char src_file[100],dst_file[100];
if(argc!=3)
{
printf("Usage:./a.out <src_file> <dst_file> n");
exit(0);
}
Else
{
strcpy(src_file,argv[1]);
strcpy(dst_file,argv[2]);
}
if((ifp=fopen(src_file,"r"))==N
ULL)
{ printf("File does not
exist.n");
exit(0);
}
if((ofp=fopen(dst_file,"w"))==
NULL)
{
printf("File not created.n");
exit(0);
}
while((c=getc(ifp))!=EOF)
{
putc(c,ofp);
}
fclose(ifp);
fclose(ofp);
}
Example: Reading command line arguments
./a.out s.dat d.dat
argc=3
./a.out
s.dat
d.dat
argv
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
printf("n My first program in C !");
getch();
}
prg1
C Language (All Concept)

More Related Content

What's hot

Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member FunctionsMuhammad Hammad Waseem
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programmingsavitamhaske
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Languagesatvirsandhu9
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 

What's hot (20)

C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Operators in c programming
Operators in c programmingOperators in c programming
Operators in c programming
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
C pointer
C pointerC pointer
C pointer
 
C presentation
C presentationC presentation
C presentation
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
Functions in c
Functions in cFunctions in c
Functions in c
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 

Viewers also liked

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointJavaTpoint.Com
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programmingavikdhupar
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS ConceptBoopathi K
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 

Viewers also liked (20)

C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Data types
Data typesData types
Data types
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Recursion
RecursionRecursion
Recursion
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
C++ OOPS Concept
C++ OOPS ConceptC++ OOPS Concept
C++ OOPS Concept
 
Recursion
RecursionRecursion
Recursion
 
Recursion
RecursionRecursion
Recursion
 
Function in c
Function in cFunction in c
Function in c
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Array in c language
Array in c languageArray in c language
Array in c language
 
C language ppt
C language pptC language ppt
C language ppt
 

Similar to C Language (All Concept)

C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptxmadhurij54
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdfHome
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniquesvalarpink
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 

Similar to C Language (All Concept) (20)

Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
C programming
C programmingC programming
C programming
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
unit 1 cpds.pptx
unit 1 cpds.pptxunit 1 cpds.pptx
unit 1 cpds.pptx
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
C notes
C notesC notes
C notes
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
c_programming.pdf
c_programming.pdfc_programming.pdf
c_programming.pdf
 
Chapter3
Chapter3Chapter3
Chapter3
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
C material
C materialC material
C material
 
C programming language
C programming languageC programming language
C programming language
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniquesugginaramesh
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 

Recently uploaded (20)

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Comparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization TechniquesComparative Analysis of Text Summarization Techniques
Comparative Analysis of Text Summarization Techniques
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 

C Language (All Concept)

  • 2. C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's Bell Laboratories in the 1972s in USA.  It is also called as 'Procedure oriented programming language.'  C is not specially designed for specific applications areas like COBOL (Common Business-Oriented Language) or FORTRAN (Formula Translation).  It is well suited for business and scientific applications.  It has some various features like control structures, looping statements, arrays, macros required for these applications.  The C language has following numerous features as:  Portability  Flexibility  Effectiveness and efficiency  Reliability  Interactivity
  • 3. Execution of C Program : C program executes in following 4 (four steps). 1.Creating a program : An editor like notepad or WordPad is used to create a C program. This file contains a source code which consists of executable code. The file should be saved as '*.c' extension only. 2.Compiling the program : The next step is to compile the program. The code is compiled by using compiler. Compiler converts executable code to binary code i.e. object code. 3.Linking a program to library : The object code of a program is linked with libraries that are needed for execution of a program. The linker is used to link the program with libraries. It creates a file with '*.exe' extension. 4.Execution of program : The final executable file is then run by dos command prompt or by any other software.
  • 4. Year of Establishment Language Name Developed By 1960 ALGOL-60 Cambridge University 1963 CPL (Combined Programming Language) Cambridge University 1967 BCPL (Basic Combined Programming Language) Martin Richard at Cambridge University 1970 B Ken Thompson at AT & T's Bell Laboratories. 1972 C Dennis Ritchie at AT & T' Bell Laboratory.
  • 5. Document Section Links Section (File) Definition Section Global variable declaration Section void main() { Variable declaration section Function declaration section executable statements; } Function definition 1 --------------------- --------------------- Function definition n where,
  • 6. where,  Document Section : It consists of set of comment lines which include name of a program, author name, creation date and other information.  Links Section (File) : It is used to link the required system libraries or header files to excute a program.  Definition Section : It is used to define or set values to variables.  Global variable declaration Section : It is used to declare global or public variable.  void main() : Used to start of actual C program. It includes two parts as declaration part and executable part.  Variable declaration section : Used to declare private variable.  Then, executable statements are placed for execution.  Function definition section : Used to define functions which are to be called from main().
  • 7. VARIABLES AND KEYWORDS  Character Set : A character refers to the digit, alphabet or special symbol used to data representation. 1. Alphabets : A-Z, a-z 2. Digits : 0-9 3. Special Characters : ~ ! @ # $ % ^ & * ( ) _ + { } [ ] - < > , . / ? | : ; " ' 4. White Spaces : Horizontal tab, Carriage return, New line  Identifier : identifier is the name of a variable that is made up from combination of alphabets, digits and underscore.  Variable : It is a data name which is used to store data and may change during program execution. It is opposite to constant. Variable name is a name given to memory cells location of a computer where data is stored. * Rules for variables: • First character should be letter or alphabet. • Keywords are not allowed to use as a variable name. • White space is not allowed. • C is case sensitive i.e. UPPER and lower case are significant. • Only underscore, special symbol is allowed between two characters.
  • 8. int float double long short signed unsigned const if else switch break default do while for register extern static struct typedef enum return sizeof goto union auto case void char continue volatile Keywords :  Keywords are the system defined identifiers.  All keywords have fixed meanings that do not change.  White spaces are not allowed in keywords.  Keyword may not be used as an identifier.  It is strongly recommended that keywords should be in lower case letters. There are totally 32(Thirty Two) keywords used in a C programming.
  • 9. Escape Sequence Characters (Backslash Character Constants) in C: C supports some special escape sequence characters that are used to do special tasks. Character Constant Meaning n New line (Line break) b Backspace t Horizontal Tab f Form feed a Alert (alerts a bell) r Carriage Return v Vertical Tab ? Question Mark ' Single Quote '' Double Quote Backslash 0 Null
  • 10. Constants in C A constant is an entity that doesn't change during the execution of a program. Syntax: const data type var_name=expression; Ex: const float pi=3.147 Followings are the different types of constants : 1. Real Constant : It must have a decimal point which may be positive or negative. Example: +194.143, -416.41 2. Integer Constant : It should not contain a decimal place. It can be positive or negative. Example: 1990, 194, -394 3. Character Constant : It is a single alphabet or a digit or a special symbol enclosed in a single quote. Maximum length of a character constant is 1. Example: 'T', '9', '$' 4. String Constant : It may contain letters, digits, special characters and blank space. Example: “Hello friends welcome"
  • 11. Data Types in C : "Data type can be defined as the type of data of variable or constant store." Keyword Format Specifier Size Data Range char %c 1 Byte -128 to +127 unsigned char <-- -- > 8 Bytes 0 to 255 int %d 2 Bytes -32768 to +32767 long int %ld 4 Bytes -231 to +231 unsigned int %u 2 Bytes 0 to 65535 float %f 4 Bytes -3.4e38 to +3.4e38 double %lf 8 Bytes -1.7e38 to +1.7e38 long double %Lf 12-16 Bytes -3.4e38 to +3.4e38 Followings are the most commonly used data types in C.
  • 12. Operator Name Operators Assignment = Arithmetic + , - , *, /, % Logical &&, ||, ! Relational <, >, <=, >=, ==, != Shorthand +=, -=, *=, /=, %= Unary ++, -- Conditional Y=(x>9)? 100 :200 ; Bitwise &, |, ^, <<, >>, ~ Operators in C : "Operator is a symbol that is used to perform operations.“  Followings are the most commonly used data types in C.
  • 13. Conditional Operator (?:) The conditional operator ?: is a ternary operator. This means that it takes in three arguments that together form a conditional expression. Syntax: exp1?exp2:exp3 Where in exp1 is a boolean expression whose result must either be true or false. If exp1 is true, exp2 is the value returned. If it is false, then exp3 is returned. For example, given the code, public class ConditionalOperator { public static void main( String[] args ){ String status = ""; int grade = 80; //get status of the student status = (grade >= 60)?"Passed":"Fail"; //print status System.out.println( status ); } } The output of this program will be, Passed
  • 14. Here is the flowchart of how ?: works,
  • 15. Increment and Decrement operators Java includes a unary increment operator (++) and decrement operator (--). Increment and decrement operators increase and decrease a value stored in a number variable by 1. For example, the expression, count = count + 1; //increment the value of count by 1 is equivalent to, count++; Operator Use Description ++ op++ Increments op by 1; evaluates to the value of op before it was incremented ++ ++op Increments op by 1;evaluates to the value of op after it was incremented -- op-- Decrements op by 1;evaluates to the value of op before it was decremented -- --op Decrements op by 1;evaluates to the value of op after it was decremented For example, int i = 10, int j = 3; int k = 0; k = ++j + i; //will result to k = 4+10 = 14 k = j++ + i; //will result to k = 3+10 = 13
  • 16. Input output statements in C printf(“ msg ”); Scanf(“format specifier ”,&var_name ); printf(“format specifier”,var_name);  printf(“msg format specifier”,var_name);
  • 17. Decision Making Statements / Conditional Statements : C program executes program sequentially. Sometimes, a program requires checking of certain conditions in program execution.  Followings are the different conditional statements used in C.  If Statement  If-Else Statement  Nested If-Else Statement  Switch Case If Statement : This is a conditional statement used in C to check condition or to control the flow of execution of statements. Syntax: if (condition) { statements; } In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the braces and executes the block of statements associated with it. If it returns false, then program skips the braces.
  • 18. If-Else Statement : This is also one of the most useful conditional statement used in C to check conditions. Syntax: if(condition) { true statements; } else { false statements; } In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the braces and executes the block of statements associated with it. If it returns false, then it executes the else part of a program.
  • 19. Nested If-Else Statement : It is a conditional statement which is used when we want to check more than 1 conditions at a time in a same program. The conditions are executed from top to bottom checking each condition whether it meets the conditional criteria or not. Syntax: if(condition) { if(condition) { statements; } else { statements; } } else { statements; } In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the braces and again checks the next condition. If it is true then it executes the block of statements associated with it else executes else part.
  • 20. Switch case Statement : This is a multiple or multiway branching decision making statement. When we use nested if-else statement to check more than 1 conditions then the complexity of a program increases in case of a lot of conditions. So to overcome this problem, C provides 'switch case'. Switch case checks the value of a expression against a case values, if condition matches the case values then the control is transferred to that point. In this syntax, switch, case, break are keywords. expr1, expr2 are known as 'case labels.' Break statement causes an exit from switch statement. Default case is optional case. When neither any match found, it executes Syntax: switch(expression) { case expr1: statements; break; case expr2: statements; break; . . case expr N: statements; break; default: Statements; break; }
  • 21. Looping Statements / Iterative Statements : 'A loop' is a part of code of a program which is executed repeatedly. A loop is used using condition. The repetition is done until condition becomes condition true. A loop declaration and execution can be done in following ways.  Check condition to start a loop  Initialize loop with declaring a variable.  Executing statements inside loop.  Increment or decrement of value of a variable. * Types of looping statements : Basically, the types of looping statements depends on the condition checking mode. Condition checking can be made in two ways as : Before loop and after loop.
  • 22. 1. Entry controlled loop : In such type of loop, the test condition is checked first before the loop is executed. Some common examples of this looping statements are :  while loop  for loop 2. Exit controlled loop : In such type of loop, the loop is executed first. Then condition is checked after block of statements are executed. The loop executed atleast one time compulsorily. Some common example of this looping statement is :  do-while loop So, there are 2(two) types of looping statements.  Entry controlled loop  Exit controlled loop
  • 23. While loop : This is an entry controlled looping statement. It is used to repeat a block of statements until condition becomes true. Syntax: while(condition) { statements; increment/decrement; } In above syntax, the condition is checked first. If it is true, then the program control flow goes inside the loop and executes the block of statements associated with it. At the end of loop increment or decrement is done to change in variable value. This process continues until test condition satisfies.
  • 24. Do-While loop : This is an exit controlled looping statement. Sometimes, there is need to execute a block of statements first then to check condition. At that time such type of a loop is used. In this, block of statements are executed first and then condition is checked. Syntax: do { statements; (increment/decrement); } while(condition); In above syntax, the first the block of statements are executed. At the end of loop, while statement is executed. If the resultant condition is true then program control goes to evaluate the body of a loop once again. This process continues till condition becomes true. When it becomes false, then the loop terminates.
  • 25. For loop : This is an entry controlled looping statement. In this loop structure, more than one variable can be initialized. One of the most important feature of this loop is that the three actions can be taken at a time like variable initialization, condition checking and increment/decrement. Syntax: for(initialization; test-condition; incre/decre) { statements; } Features :  More concise  Easy to use  Highly flexible  More than one variable can be initialized.  More than one increments can be applied.  More than two conditions can be used.
  • 26.  Break Statement : Sometimes, it is necessary to exit immediately from a loop as soon as the condition is satisfied. When break statement is used inside a loop, then it can cause to terminate from a loop. The statements after break statement are skipped.  Continue Statement : Sometimes, it is required to skip a part of a body of loop under specific conditions. So, C supports 'continue' statement to overcome this problem. The working structure of 'continue' is similar as that of that break statement but difference is that it cannot terminate the loop. Continue statement simply skips statements and continues next iteration. Syntax : break; While(condition) { - - - - - - - - - - - break; - - - - - - } Syntax : continue; While(condition) { - - - - - - - - - - - Continue; - - - - - - - - }
  • 27. Goto Statement : It is a well known as 'jumping statement.' It is primarily used to transfer the control of execution to any place in a program. It is useful to provide branching within a loop. When the loops are deeply nested at that if an error occurs then it is difficult to get exited from such loops. Simple break statement cannot work here properly. In this situations, goto statement is used. Syntax : goto [expr]; While(condition) { - - - - - - - - - - - goto label; - - - - - - label: } While(condition) { - - - - - label: - - - - - - - - goto label; - - - }
  • 28. Functions in C : The function is a self contained block of statements which performs a coherent task of a same kind. Types of functions : • Built in Functions • User Defined Functions 1. Built in Functions : These functions are also called as 'library functions'. These functions are provided by system. These functions are stored in library files. e.g. scanf() printf() strcpy() strlwr() strcmp() strlen() strcat()
  • 29. 2.User Defined Functions : The functions which are created by user for program are known as 'User defined functions'. Advantages :  It is easy to use, It reduces the size of a program.  Debugging is more suitable for programs.  It is easy to understand the actual logic of a program.  Highly suited in case of large programs.  By using functions in a program, it is possible to construct modular and structured programs. Syntax: // Function definition <return_type> <function_name>(argu_list); void main() { // Function Call <function_name>(<arguments>); } // Function declaration <return_type><function_name>(<argu_list>) { <function_body>; }
  • 30. FUNCTION TYPES: 1) Function with No arguments and No return value 2) Function with arguments but No return value 3) Function with No arguments but Returns a value 4) Function with arguments and return values 5) Function with multiple return values
  • 31. In this ex. a & b are actual arguments & x is formal argument
  • 32.
  • 33.  Some Points about functions:  A function cannot be defined within another function.  All function definitions must be disjoint.  Nested function calls are allowed. A calls B, B calls C, C calls D, etc. The function called last will be the first to return.  A function can also call itself, either directly or in a cycle. A calls B, B calls C, C calls back A. Called recursive call or recursion.  Calling Functions :Call by value and call by reference Used when invoking functions  Call by Value:  Copy of argument pass to a function  Changes in function do not effect original  Call by reference:  Passes original arguments to a function  Changes in function effect original
  • 34. Recursion •A process by which a function calls itself repeatedly. –Either directly. •X calls X. –Or cyclically in a chain. •X calls Y, and Y calls X. •Used for repetitive computations in which each action is stated in terms of a previous result. fact(n) = n * fact (n-1) For a problem to be written in recursive form, two conditions are to be satisfied: –It should be possible to express the problem in recursive form. –The problem statement must include a stopping condition fact(n) = 1, if n = 0 = n * fact(n-1), if n > 0
  • 35.  More example on recursion: –GCD: gcd(m, m) = m Gcd(m, n) = gcd(m-n, n), if m > n gcd(m, n) = gcd(n, n-m), if m < n –Fibonacci series (1,1,2,3,5,8,13,21,….) fib (0) = 1 fib (1) = 1 fib (n) = fib (n-1) + fib (n-2), if n > 1  Mechanism of Execution: -When a recursive program is executed, the recursive function calls are not executed immediately. –They are kept aside (on a stack) until the stopping condition is encountered. –The function calls are then executed in reverse order.
  • 36.  Storage Class : 'Storage' refers to the scope of a variable and memory allocated by compiler to store that variable. Scope of a variable is the boundary within which a variable can be used. Storage class defines the the scope and lifetime of a variable.  Functions of storage class :  To determine the location of a variable where it is stored ?  Set initial value of a variable or if not specified then setting it to default value.  Defining scope of a variable.  To determine the life of a variable.  Types of Storage Classes : Storage classes are categorized in 4 (four) types as, 1. Automatic storage class 2. Register storage class 3. Static storage class 4. External storage class
  • 37.  Automatic Storage Class :  Keyword : auto  Storage Location : Main memory  Initial Value : Garbage Value  Life : Control remains in a block where it is defined.  Scope : Local to the block in which variable is declared. Syntax : auto [data_type] [variable_name]; Example : auto int a;  Register Storage Class :  Keyword : register  Storage Location : CPU Register  Initial Value : Garbage  Life : Local to the block in which variable is declared.  Scope : Local to the block. Syntax : register [data_type] [variable_name]; Example : register int a;
  • 38.  Static Storage Class :  Keyword : static  Storage Location : Main memory  Initial Value : Zero and can be initialize once only.  Life : depends on function calls and the whole application or program.  Scope : Local to the block. Syntax : static [data_type] [variable_name]; Example : static int a;  External Storage Class :  Keyword : extern  Storage Location : Main memory  Initial Value : Zero  Life : Until the program ends.  Scope : Global to the program. Syntax : extern [data_type] [variable_name]; Example : extern int a;
  • 39.  Array : Array is a fixed sized sequenced collection of the elements of the same data type .‘  Types of an Array : 1) Single / One Dimensional Array 2) Two Dimensional Array  Single / One Dimensional Array : The array which is used to represent and store data in a linear form is called as 'single or one dimensional array.‘ Syntax: <data-type> <array_name> [size];  Memory Allocation: A[0] A[1] A[2] A[n] 5 7 2 12 1000 1002 1004 n A[i] element address
  • 40.  Two Dimensional Array : The array which is used to represent and store data in a tabular form is called as 'two dimensional array.' Such type of array specially used to represent data in a matrix form. The following syntax is used to represent two dimensional array. Syntax: <data-type> <array_name> [row_size][column_size]; Example: int a[3][3]; It is also called as 'multidimensional array.' a[0][0] a[0][1] a[0][2] a[1][0] a[1][1] a[1][2] a[2][0] a[2][1] a[2][2] i row j a[i][j] Memory allocation for two dimensional array  Limitations of two dimensional array :  We cannot delete any element from an array.  If we don't know that how many elements have to be stored in a memory in advance, then there will be memory wastage if large array size is specified.
  • 41. “Structure “ Structure is user defined data type which is used to store heterogeneous data under unique name. Keyword 'struct' is used to declare structure. The variables which are declared inside the structure are called as 'members of structure'. Syntax: struct structure_nm { <data-type> element 1; <data-type> element 2; - - - - - - - - - - - - - - - - - - - - - <data-type> element n; }struct_var; * Accessing Structure Members : Structure members can be accessed using member operator '.' . It is also called as 'dot operator' or 'period operator'. structure_var.member;
  • 42. Structures within Structures (Nested Structures) : Structures can be used as structures within structures. It is also called as 'nesting of structures'. Syntax: struct structure_nm { <data-type> element 1; <data-type> element 2; - - - - - - - - - - - - - - - - - - - - - <data-type> element n; struct structure_nm { <data-type> element 1; <data-type> element 2; - - - - - - - - - - - - - - - - - - - - - - <data-type> element n; }inner_struct_var; }outer_struct_var;
  • 43. Union Union is user defined data type used to stored data under unique variable name at single memory location. Syntax of union is similar to structure. But the major difference between structure and union is 'storage.' In structures, each member has its own storage location, whereas all the members of union use the same location. Union contains many members of different types, it can handle only one member at a time. Syntax: union union_name { <data-type> element 1; <data-type> element 2; <data-type> element 3; }union_variable; Example: union techno { int comp_id; char nm; float sal; }tch; Memory Allocation To access union members, we can use the following syntax. tch.comp_id tch.nm tch.sal
  • 44. POINTER Pointer is a variable which holds the memory address of another variable. Pointers are represented by '*'. It is a derive data type in C. Pointer returns the value of stored address. Syntax: <data_type> *pointer_name; int *tot; int tot = 95; In above syntax, * = variable pointer_name is a pointer variable. pointer_name requires memory location pointer_name points to a variable of type data type.  Features of Pointer : * Pointer variable should have prefix '*'. * Combination of data types is not allowed. * Pointers are more effective and useful in handling arrays. * It can also be used to return multiple values from a function using function arguments. * It supports dynamic memory management. * It reduces complexity and length of a program. * It helps to improve execution speed that results in reducing program execution time.
  • 45. String : A string is a collection of characters. Strings are always enlosed in double quotes as "string_constant". Strings are used in string handling operations such as, •Counting the length of a string. •Comparing two strings. •Copying one string to another. •Converting lower case string to upper case. •Converting upper case string to lower case. •Joining two strings. •Reversing string. Declaration Syntax: char string_nm[size]; Example: char name[50]; String Handling in C
  • 46. Read Strings : To read a string, we can use scanf() function with format specifier %s. char name[50]; scanf("%s",name); Write Strings : To write a string, we can use printf() function with format specifier %s. char name[50]; scanf("%s",name); printf("%s",name); String Structure : When compiler assigns string to character array then it automatically supplies null character ('0') at the end of string. Thus, size of string = original length of string + 1. char name[7]; name = "TECHNO"
  • 47. Function Name Description n=strlen (s1) Returns the length of a string. strlwr (s1) Returns upper case letter to lower case. strupr (s1) Returns lower case letter to upper case. strcat (s1,s2) Concatenates two string. strcmp (s1,s2) Compares two strings. strrev (s1) Returns length of a string. strcpy (s1,s2) Copies a string from source to destination. String handling functions:
  • 48. File handling in C In C we use FILE * to represent a pointer to a file. •fopen is used to open a file. It returns the special value NULL to indicate that it couldn't open the file. FILE *fptr; char filename[]= "file2.dat"; fptr= fopen(filename,"w"); if (fptr== NULL) { printf(“ERROR IN FILE CREATION”); /* DO SOMETHING */ }
  • 49.  Modes for opening files •The second argument of fopen is the mode in which we open the file. •"r"opens a file for reading •"w"creates a file for writing -and writes over all previous contents (deletes the file so be careful!) •"a"opens a file for appending -writing on the end of the file •“rb”read binary file (raw bytes) •“wb”write binary file  The exit() function •Sometimes error checking means we want an "emergency exit" from a program. We want it to stop dead. •In main we can use "return" to stop. •In functions we can use exit to do this. •Exit is part of the stdlib.h library exit(-1); in a function is exactly the same as return -1; in the main routine
  • 50. Writing to a file using fprintf( ): fprintf( ) works just like printf and sprintf except that its first argument is a file pointer. FILE *fptr; fptr= fopen("file.dat","w"); /* Check it's open */ fprintf(fptr,"Hello World!n"); FILE *fptr; fptr= fopen("file.dat","w"); /* Check it's open */ fprintf(fptr,"Hello World!n");
  • 51.  Reading Data Using fscanf( ) •We also read data from a file using fscanf( ). FILE *fptr; fptr= fopen(“input.dat”,“r”); /* Check it's open */ if (fptr==NULL) { printf(“Error in opening file n”); } fscanf(fptr,“%d%d”,&x,&y); 20 30 input.dat x=20 y=30
  • 52.  Reading lines from a file using fgets( ) We can read a string using fgets( ). fgets( ) takes 3 arguments, a string, a maximum number of characters to read and a file pointer. It returns NULL if there is an error. FILE *fptr; char line [1000]; /* Open file and check it is open */ while (fgets(line,1000,fptr)!= NULL) { printf("Read line %sn",line); }
  • 53. Closing a file •We can close a file simply using fclose( )and the file pointer. FILE *fptr; char filename[]= "myfile.dat"; fptr= fopen(filename,"w"); if (fptr== NULL) { printf("Cannot open file to write!n"); exit(-1); } fprintf(fptr,"Hello World of filing!n"); fclose(fptr); Opening Closing Access
  • 54. Three special streams Three special file streams are defined in the <stdio.h> header •stdin reads input from the keyboard •stdout send output to the screen •stderr prints errors to an error device (usually also the screen) Ex: fprintf(stdout,"Hello World!n");
  • 55. Input File & Output File redirection •One may redirect the input and output files to other files (other than stdinand stdout). •Usage: Suppose the executable file is a.out $./a.out <in.dat>out.dat in.dat 15 Give value of i Value of i=15 out.dat No error: But an example to show error message Display screen
  • 56.  Reading and Writing a character •A character reading/writing is equivalent to reading/writing a byte. intgetchar( ); intfgetc(FILE *fp); intputchar(int c); intfputc(intc, FILE *fp);  Program use of getchar() and putchar(): #include<stdio.h> main() { int c; printf("Type text and press return to see it again n"); printf("For exiting press <CTRL D> n"); while((c=getchar( ))!=EOF) putchar(c); }  Example: char c; c=getchar( ); putchar(c);
  • 57.  Command Line Arguments: Command line arguments may be passed by specifying them under main( ). int main(int argc, char *argv[ ]); Argument count Array of Strings as command line arguments including the command itself.
  • 58. #include<stdio.h> #include<string.h> int main(int argc,char *argv[]) { FILE *ifp,*ofp; int i,c; char src_file[100],dst_file[100]; if(argc!=3) { printf("Usage:./a.out <src_file> <dst_file> n"); exit(0); } Else { strcpy(src_file,argv[1]); strcpy(dst_file,argv[2]); } if((ifp=fopen(src_file,"r"))==N ULL) { printf("File does not exist.n"); exit(0); } if((ofp=fopen(dst_file,"w"))== NULL) { printf("File not created.n"); exit(0); } while((c=getc(ifp))!=EOF) { putc(c,ofp); } fclose(ifp); fclose(ofp); } Example: Reading command line arguments ./a.out s.dat d.dat argc=3 ./a.out s.dat d.dat argv
  • 59. #include <stdio.h> #include <conio.h> void main() { clrscr(); printf("n My first program in C !"); getch(); } prg1