SlideShare a Scribd company logo
Introduction to C programming
Introduction to C programming
• C is a programming language developed by AT & T Bell Laboratories of USA in
1972. It was designed and written by Dennis Ritchie. C is reliable and easy to
use. C language is a base to learn different programming language.
• If you want to learn C++ or JAVA, without the knowledge of C it becomes very
difficult to learn these programming languages. Many major components of
popular operating systems like Windows, UNIX, LINUX is still written in C.
Nothing beats C in terms of Speed of Execution.
Structure of C
A C program basically has the
following form:
• Pre-processor Commands
• Functions
• Variables
• Statements & Expressions
• Comments
Sample C program:
#include <stdio.h> // Pre-
processor Commands
int main() // Main Function
{
/* My first program */ //
Comments
printf("Hello, World! n"); //
Statements
return 0;
}
Tokens
Tokens are the basic building blocks in a C language which are
constructed together to write a C program.
Types:
• 1. Keywords (E.g. switch, int)
• 2. Identifiers (E.g. main, total)
• 3. Constants (E.g. 10,30)
• 4. Strings (E.g. “hello”, “welcome”)
• 5. Special symbols (E.g. (),{})
• 6. Operators (E.g. +,*,/,-)
Example
int main()
{
int x,y,sum;
x=5;
y=10;
sum = x+y;
printf(“sum= %d”, sum);
getch();
}
where,
main, sum – Identifier
int – Keyword
x, y, sum – Identifier
(,),{,} – Delimiter
sum, int, x, y, (, ), {, } – Tokens
The real time application
program where Token is used are Real
time calculator and Real time Bank
application programs.
Keywords
Keywords are the predefined words which is meant for
specific purpose in a C program. Since, keywords are the
referred names for complier, they can’t be used as variable
name.
32 keywords are there in C language.
Keywords types
Note:
• C is a case sensitive language.
• White spaces (tab space and space bar) are ignored.
• Each and every statement must be terminated with a semicolo
• Multiple statements can be on the same line.
• Statements can continue over multiple statements.
C Character set:
Any alphabet, digit or special
symbol can be termed as a character.
Below shows list of valid alphabets,
digits and symbols allowed in C.
Alphabets:
A, B, C, D, …, X, Y, Z
a, b, c, d, … ,x, y, z
Digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols:
~ ‘ ! @ # % ^ &amp; * ( ) _ - +
= |  { }
[ ] : ; " ' < > , . ? /
Data types
Primary data types
1. Character
2. Integer
3. Float
4. Double
Secondary data types
1. structure
2. Union
3. Pointer
4. enum
Primary data types
Secondary data types
1.Type Definition
Example:
typedef int age;
age male, female;
2.Enumerated Data type
Example :
enum
mon{jan,feb,mar,apr,may,jun,jul,
aug,sep,oct,nov,dec };
Input/Output Functions
Input functions:
scanf() function: This is the
function which can be used to to
read an input from the command
line.
Example:
int a;
printf(“Enter the number n");
scanf("%d",&a);
Output functions:
printf() function: This is one
of the most frequently used
functions in C for output.
Example:
printf("Enter an integer: ");
Format Specifier
• %d (%i) - integer
• %f - float
• %lf - double
• %c - character
• %s – String
• %u - address(pointer)
OPERATORS
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
• Misc Operators
Decision Making Statements
• Programs should be able to make logical (true/false)
decisions based on the condition they are in; every program
has one or few problem/s to solve.
Types:
• if statement
• if-else statement
• Nested if statement
• else-if ladder statement
• Switch case statement
if statement
Definition:
if (condition) { code here if “true”}
Example:
if(rate==1)
{
printf("nit is poor");
}
if-else statement
Definition:
if(condition){ code when true } else { code when
not true }
Example:
if(A>B)
{ printf(“A is greater"); }
else
{ printf(“B is greater"); }
else if ladder statement
Definition:
if(condition a)
{ statements }
else if (condition b)
{ Statement b }
else
{ statement }
Example:
if(c<a>b)
{ printf(“a is greater”);}
else if(a<b>c)
{ printf(“b is greater”);
else if(b<c>a)
{ printf(“c is greater);}
else
{ printf(“all are equal”); }
Switch case statement
Definition:
Switch (variable)
{
Case 1: statement1 break;
Case 2: statement 2 break; 40
Case 3:statement 3 break;
…..
Default: default statement
break;
}
Example:
Switch(week)
{
Case 1:printf(“Sunday”);break;
Case 2:printf(“Monday”); break;
Case 3:printf(“Tuesday”); break;
Case 4:printf(“Wednesday”);
break;
Case 5:printf(“Thursday”); break;
Default:printf(“---------”); break;
}
Looping statements
For Loop Syntax
for(initialization statement; test
expression; update statement)
{
code/s to be executed;
}
Example:
for(i=1;i<=n;i++)
{
printf(“%d”,i)
}
While loop:
while (test expression)
{
statement/s to be executed.
}
Example:
while(i<=n)
{
printf(“%d”,i);
i++;
}
do...while loop:
do
{
some codes;
}
while (test expression);
Example :
do
{ printf(“%d“,i);
i++;
} while(i<=n);
Functions
Two types:
1.built-in functions
2.User defined functions
2.1 without parameters
2.2 with parameters
Passing parameters:
• call by value
• Call by reference
Call by value:
void add(int,int);
void main()
{
add(5,10);
add(10,20);
getch();
}
void add(int a,int b)
{
int c;
c=a+b;
printf(“%d”,c);
}
Call by reference:
void disp(int);
void main()
{
int i;
printf(“enter the no”);
scanf(“%d”,&i);
disp(&i);
printf(“%d”,i);
}
void disp(int *a)
{
*a=*a+10;
Printf(“%d”,*a);
}
Arrays
Collection of similar data
type
Syntax;
Datatype Arrayname[size];
Example: INTEGER
DATA TYPE
Int a[20];
for(i=0;i<=19;i++)
{
Scanf(“%d”,a[i]);
}
Example:char data type
Void main()
{
Char s[50];
Printf(“enter the name”);
Gets(s);
Puts(s);
}
Pointers
• Pointers may reference a function or an object.
• The value of a pointer is the address of the corresponding object or
function
• Examples: int *i; char *x;
Example:
Void main()
{
int a=10;
int *p;
p=&a;
printf(“the address is %u”,p);
printf(“the value is %d”,*p);
}
Structures
• A structure is a collection of one or more components (members),
which may be of different types.
Syntax:
Struct structname;
{
datatype variable;
} s1, s2 ……….;
Example:
Struct emp
{
int id;float sal;
}e;
Void main()
{
Printf(“enter the id”);
Scanf(“%d”,e.id);
Printf(“enter the sal”);
Scanf(“%d”,e.sal);
Printf(“your id is %d”,e.id);
printf(“your salary is %d”,e.salary);
}
Unions
Example:
union emp
{
int id;float sal;
}e;
Void main()
{
Printf(“enter the id”);
Scanf(“%d”,e.id);
Printf(“enter the sal”);
Scanf(“%d”,e.sal);
Printf(“your id is %d”,e.id);
printf(“your salary is %d”,e.salary);
}
File handling
File Operations
• Creating a new file
• Opening an existing file
• Reading from and writing information to a file
• Closing a file
Working with file
• While working with file, you need to declare a pointer of type file.
This declaration is needed for communication between file and
program.
FILE *ptr;
Opening a file:
• Opening a file is performed using library function fopen().
Syntax:
ptr=fopen("fileopen", mode")
For Example:
fopen("E:cprogramprogram.txt","w");
Closing a File:
• The file should be closed after reading/writing of a file.
Closing a file is performed using library function fclose().
fclose(ptr);
//ptr is the file pointer associated with file to be
closed
example:
void main()
{
file *ptr;
int a;
ptr=fopen(“d:pg.txt”,”w”);
if(ptr==null)
{
printf(“error”);
exit(1);
}
else
{
scanf(“%d”,&a);
fprintf(ptr,”%d”,a);
printf(“successfully writed”);
}
fclose(ptr);

More Related Content

PPTX
C++ presentation
PPSX
Break and continue
PPT
Basic concept of OOP's
PPT
PPTX
Programming in C Presentation upto FILE
PPTX
PPT
screen output and keyboard input in js
PPTX
C language ppt
C++ presentation
Break and continue
Basic concept of OOP's
Programming in C Presentation upto FILE
screen output and keyboard input in js
C language ppt

What's hot (20)

PPTX
C++ Overview PPT
PPTX
Object Oriented Programming Using C++
PPTX
PPTX
Loops in C Programming Language
PPTX
Type conversion
PPT
C by balaguruswami - e.balagurusamy
PPTX
C Programming: Control Structure
PPTX
Pointers in c++
PPTX
Python Programming Language
PPTX
C tokens
PPSX
INTRODUCTION TO C PROGRAMMING
PPTX
Functions in c language
PPTX
Data types
PDF
Let us c yashwant kanetkar(1)
PDF
Differences between c and c++
PPT
Characteristics of c#
PDF
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
PPTX
Data types in c++
PPTX
This pointer
PPT
Variables in C Programming
C++ Overview PPT
Object Oriented Programming Using C++
Loops in C Programming Language
Type conversion
C by balaguruswami - e.balagurusamy
C Programming: Control Structure
Pointers in c++
Python Programming Language
C tokens
INTRODUCTION TO C PROGRAMMING
Functions in c language
Data types
Let us c yashwant kanetkar(1)
Differences between c and c++
Characteristics of c#
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
Data types in c++
This pointer
Variables in C Programming
Ad

Similar to C introduction by thooyavan (20)

DOC
1. introduction to computer
PPTX
Programming Fundamentals
PPTX
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
PPTX
C programming language:- Introduction to C Programming - Overview and Importa...
PPTX
C Language ppt create by Anand & Sager.pptx
PPT
The smartpath information systems c pro
PPTX
C lang7age programming powerpoint presentation
PPTX
C programming language tutorial
PPTX
C language (1).pptxC language (1C language (1).pptx).pptx
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
PPTX
C Programming - Basics of c -history of c
PDF
EC2311-Data Structures and C Programming
PPTX
C programming tutorial for Beginner
PPTX
C language
PPT
C programming
PPTX
Introduction to C Unit 1
PPTX
C for Engineers
PPTX
Introduction to c
PPTX
Fundamental programming Nota Topic 2.pptx
PDF
Getting Started with C Programming: A Beginner’s Guide to Syntax, Variables, ...
1. introduction to computer
Programming Fundamentals
Team-7 SP.pptxdfghjksdfgduytredfghjkjhgffghj
C programming language:- Introduction to C Programming - Overview and Importa...
C Language ppt create by Anand & Sager.pptx
The smartpath information systems c pro
C lang7age programming powerpoint presentation
C programming language tutorial
C language (1).pptxC language (1C language (1).pptx).pptx
Esoft Metro Campus - Certificate in c / c++ programming
C Programming - Basics of c -history of c
EC2311-Data Structures and C Programming
C programming tutorial for Beginner
C language
C programming
Introduction to C Unit 1
C for Engineers
Introduction to c
Fundamental programming Nota Topic 2.pptx
Getting Started with C Programming: A Beginner’s Guide to Syntax, Variables, ...
Ad

More from Thooyavan Venkatachalam (6)

PPTX
Import data MySQL to Excel & Excel to MySQL
PPTX
OOPS Basics With Example
DOCX
Career After B.A in Eng(lit)
PPTX
Groupdiscussion
PPTX
PPT
advanced security system for women
Import data MySQL to Excel & Excel to MySQL
OOPS Basics With Example
Career After B.A in Eng(lit)
Groupdiscussion
advanced security system for women

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
Insiders guide to clinical Medicine.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
master seminar digital applications in india
Classroom Observation Tools for Teachers
Insiders guide to clinical Medicine.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial disease of the cardiovascular and lymphatic systems
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Final Presentation General Medicine 03-08-2024.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
human mycosis Human fungal infections are called human mycosis..pptx
Week 4 Term 3 Study Techniques revisited.pptx
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

C introduction by thooyavan

  • 1. Introduction to C programming
  • 2. Introduction to C programming • C is a programming language developed by AT & T Bell Laboratories of USA in 1972. It was designed and written by Dennis Ritchie. C is reliable and easy to use. C language is a base to learn different programming language. • If you want to learn C++ or JAVA, without the knowledge of C it becomes very difficult to learn these programming languages. Many major components of popular operating systems like Windows, UNIX, LINUX is still written in C. Nothing beats C in terms of Speed of Execution.
  • 3. Structure of C A C program basically has the following form: • Pre-processor Commands • Functions • Variables • Statements & Expressions • Comments Sample C program: #include <stdio.h> // Pre- processor Commands int main() // Main Function { /* My first program */ // Comments printf("Hello, World! n"); // Statements return 0; }
  • 4. Tokens Tokens are the basic building blocks in a C language which are constructed together to write a C program. Types: • 1. Keywords (E.g. switch, int) • 2. Identifiers (E.g. main, total) • 3. Constants (E.g. 10,30) • 4. Strings (E.g. “hello”, “welcome”) • 5. Special symbols (E.g. (),{}) • 6. Operators (E.g. +,*,/,-)
  • 5. Example int main() { int x,y,sum; x=5; y=10; sum = x+y; printf(“sum= %d”, sum); getch(); } where, main, sum – Identifier int – Keyword x, y, sum – Identifier (,),{,} – Delimiter sum, int, x, y, (, ), {, } – Tokens The real time application program where Token is used are Real time calculator and Real time Bank application programs.
  • 6. Keywords Keywords are the predefined words which is meant for specific purpose in a C program. Since, keywords are the referred names for complier, they can’t be used as variable name. 32 keywords are there in C language.
  • 8. Note: • C is a case sensitive language. • White spaces (tab space and space bar) are ignored. • Each and every statement must be terminated with a semicolo • Multiple statements can be on the same line. • Statements can continue over multiple statements.
  • 9. C Character set: Any alphabet, digit or special symbol can be termed as a character. Below shows list of valid alphabets, digits and symbols allowed in C. Alphabets: A, B, C, D, …, X, Y, Z a, b, c, d, … ,x, y, z Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Special Symbols: ~ ‘ ! @ # % ^ &amp; * ( ) _ - + = | { } [ ] : ; " ' < > , . ? /
  • 10. Data types Primary data types 1. Character 2. Integer 3. Float 4. Double Secondary data types 1. structure 2. Union 3. Pointer 4. enum
  • 12. Secondary data types 1.Type Definition Example: typedef int age; age male, female; 2.Enumerated Data type Example : enum mon{jan,feb,mar,apr,may,jun,jul, aug,sep,oct,nov,dec };
  • 13. Input/Output Functions Input functions: scanf() function: This is the function which can be used to to read an input from the command line. Example: int a; printf(“Enter the number n"); scanf("%d",&a); Output functions: printf() function: This is one of the most frequently used functions in C for output. Example: printf("Enter an integer: ");
  • 14. Format Specifier • %d (%i) - integer • %f - float • %lf - double • %c - character • %s – String • %u - address(pointer)
  • 15. OPERATORS • Arithmetic Operators • Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators • Misc Operators
  • 16. Decision Making Statements • Programs should be able to make logical (true/false) decisions based on the condition they are in; every program has one or few problem/s to solve. Types: • if statement • if-else statement • Nested if statement • else-if ladder statement • Switch case statement
  • 17. if statement Definition: if (condition) { code here if “true”} Example: if(rate==1) { printf("nit is poor"); }
  • 18. if-else statement Definition: if(condition){ code when true } else { code when not true } Example: if(A>B) { printf(“A is greater"); } else { printf(“B is greater"); }
  • 19. else if ladder statement Definition: if(condition a) { statements } else if (condition b) { Statement b } else { statement } Example: if(c<a>b) { printf(“a is greater”);} else if(a<b>c) { printf(“b is greater”); else if(b<c>a) { printf(“c is greater);} else { printf(“all are equal”); }
  • 20. Switch case statement Definition: Switch (variable) { Case 1: statement1 break; Case 2: statement 2 break; 40 Case 3:statement 3 break; ….. Default: default statement break; } Example: Switch(week) { Case 1:printf(“Sunday”);break; Case 2:printf(“Monday”); break; Case 3:printf(“Tuesday”); break; Case 4:printf(“Wednesday”); break; Case 5:printf(“Thursday”); break; Default:printf(“---------”); break; }
  • 21. Looping statements For Loop Syntax for(initialization statement; test expression; update statement) { code/s to be executed; } Example: for(i=1;i<=n;i++) { printf(“%d”,i) }
  • 22. While loop: while (test expression) { statement/s to be executed. } Example: while(i<=n) { printf(“%d”,i); i++; }
  • 23. do...while loop: do { some codes; } while (test expression); Example : do { printf(“%d“,i); i++; } while(i<=n);
  • 24. Functions Two types: 1.built-in functions 2.User defined functions 2.1 without parameters 2.2 with parameters Passing parameters: • call by value • Call by reference
  • 25. Call by value: void add(int,int); void main() { add(5,10); add(10,20); getch(); } void add(int a,int b) { int c; c=a+b; printf(“%d”,c); } Call by reference: void disp(int); void main() { int i; printf(“enter the no”); scanf(“%d”,&i); disp(&i); printf(“%d”,i); } void disp(int *a) { *a=*a+10; Printf(“%d”,*a); }
  • 26. Arrays Collection of similar data type Syntax; Datatype Arrayname[size]; Example: INTEGER DATA TYPE Int a[20]; for(i=0;i<=19;i++) { Scanf(“%d”,a[i]); } Example:char data type Void main() { Char s[50]; Printf(“enter the name”); Gets(s); Puts(s); }
  • 27. Pointers • Pointers may reference a function or an object. • The value of a pointer is the address of the corresponding object or function • Examples: int *i; char *x; Example: Void main() { int a=10; int *p; p=&a; printf(“the address is %u”,p); printf(“the value is %d”,*p); }
  • 28. Structures • A structure is a collection of one or more components (members), which may be of different types. Syntax: Struct structname; { datatype variable; } s1, s2 ……….;
  • 29. Example: Struct emp { int id;float sal; }e; Void main() { Printf(“enter the id”); Scanf(“%d”,e.id); Printf(“enter the sal”); Scanf(“%d”,e.sal); Printf(“your id is %d”,e.id); printf(“your salary is %d”,e.salary); }
  • 30. Unions Example: union emp { int id;float sal; }e; Void main() { Printf(“enter the id”); Scanf(“%d”,e.id); Printf(“enter the sal”); Scanf(“%d”,e.sal); Printf(“your id is %d”,e.id); printf(“your salary is %d”,e.salary); }
  • 31. File handling File Operations • Creating a new file • Opening an existing file • Reading from and writing information to a file • Closing a file Working with file • While working with file, you need to declare a pointer of type file. This declaration is needed for communication between file and program. FILE *ptr;
  • 32. Opening a file: • Opening a file is performed using library function fopen(). Syntax: ptr=fopen("fileopen", mode") For Example: fopen("E:cprogramprogram.txt","w"); Closing a File: • The file should be closed after reading/writing of a file. Closing a file is performed using library function fclose(). fclose(ptr); //ptr is the file pointer associated with file to be closed
  • 33. example: void main() { file *ptr; int a; ptr=fopen(“d:pg.txt”,”w”); if(ptr==null) { printf(“error”); exit(1); } else { scanf(“%d”,&a); fprintf(ptr,”%d”,a); printf(“successfully writed”); } fclose(ptr);