SlideShare a Scribd company logo
Unit - 2
Mithun D’Souza
Assistant Professor,
Department of Computer Science,
PES Institute of Advanced Management Studies,
Shivamogga
 C is a general-purpose, high-level language that was originally
developed by Dennis M. Ritchie to develop the UNIX operating
system at Bell Labs.
 C was originally first implemented on the DEC PDP-11 computer in
1972.
 In 1978, Brian Kernighan and Dennis Ritchie produced the first
publicly available description of C, now known as the K&R standard.
 The UNIX operating system, the C compiler, and essentially all
UNIX application programs have been written in C.
 In 1988, the American National Standards Institute (ANSI) had
formalized the C language.
 C was invented to write UNIX operating system.
 C is a successor of 'Basic Combined Programming Language' (BCPL)
called B language.
 Linux OS, PHP, and MySQL are written in C.
 C has been written in assembly language
Unit 2   introduction to c programming
 C has now become a widely used professional language for
various reasons:
 Easy to learn
 Structured language
 It produces efficient programs
 It can handle low-level activities
 It can be compiled on a variety of computer platforms
 C was invented to write an operating system called UNIX.
 C is a successor of B language which was introduced around the early
1970s.
 The language was formalized in 1988 by the American National
Standard Institute (ANSI).
 The UNIX OS was totally written in C.
 Today C is the most widely used and popular System Programming
Language.
 Most of the state-of-the-art software have been implemented using C.
 Today's most popular Linux OS and RDBMS MySQL have been
written in C.
 C was initially used for system development work, particularly the
programs that make-up the operating system.
 C was adopted as a system development language because it produces
code that runs nearly as fast as the code written in assembly language.
 Operating Systems
 Language Compilers
 Assemblers
 Text Editors
 Print Spoolers
 Network Drivers
 Modern Programs
 Databases
 Language Interpreters
 Utilities
Unit 2   introduction to c programming
 In C, compiler is a special tool that compiles the program and
converts it into the object file which is machine readable.
 After the compilation process, the linker will combine different object
files and creates a single executable file to run the program.
 General purpose Programming Language
 Structured Programming Language
 Helps in the development of System Software
 Rich set of Operators
 Provides compact representation for expressions
 Allows manipulation of internal processor registers
 No rigid format: Any Number of statement can be typed in a single line
 Portability: any C program can be run on different machines with little or no
modification
 Supports a rich set of data types
 Very less number of reserved words
 Pointer arithmetic and pointer manipulation
 Ability to extend itself by adding functions to its library
Unit 2   introduction to c programming
 System Software
 Operating systems
 Compilers
 Assemblers
 Editors
 Loaders
 Linkers
 Application Software
 Database Management Systems (DBMS)
 Graphics Packages
 Spread sheets
 CAD/CAM applications
 Word Processors
 Office Automation Tools
 Scientific and Engineering applications
1) Comment line
2) Preprocessor directive
3) Global variable declaration
4) main function( )
{
Local variables;
Statements;
}
User defined function ( )
{
// user defined instructions/ statements
}
Unit 2   introduction to c programming
 It indicates the purpose of the program. It is represented as
/*……………………………..*/
 Comment line is used for increasing the readability of the program.
 It is useful in explaining the program and generally used for
documentation.
 It is enclosed within the decimeters.
 Comment line can be single or multiple line but should not be
nested.
 It can be anywhere in the program except inside string constant &
character constant.
 #include<stdio.h> tells the compiler to include information about the
standard input/output library.
 It is also used in symbolic constant such as #define PI 3.14(value).
 The stdio.h (standard input output header file)
 contains definition &declaration of system defined function such as
 printf( ) - Printing on screen
 scanf( ) - Reading data from user
 pow( ) etc.
 Generally printf() function used to display and scanf() function used
to read value
Unit 2   introduction to c programming
 This is the section where variable are declared globally
 It can be access by all the functions used in the program.
 And it is generally declared outside the function
 It is the user defined function and every function has one main()
function from where actually program is started and it is encloses
within the pair of curly braces.
 The main( ) function can be anywhere in the program but in general
practice it is placed in the first position.
Syntax :
main()
{
……..
……..
……..
}
 The main( ) function return value when it declared by data type as
int main( )
{
return 0
}
 The main function does not return any value when void (means
null/empty) as
void main(void ) or void main()
{
printf (“C language”);
}
Output: C language
 The program execution start with opening braces and end with closing
brace.
 And in between the two braces declaration part as well as executable part is
mentioned.
 And at the end of each line, the semi-colon is given which indicates
statement termination.
/*First c program with return statement*/
#include <stdio.h>
int main (void)
{
printf ("welcome to c Programming language.n");
return 0;
}
Output: welcome to c programming language.
 A compiler is a software program that analyzes a program developed
in a particular computer language and then translates it into a form
that is suitable for execution on a particular computer system.
 The steps involves
 entering,
 compiling, and
 executing a computer program
 Which are developed in the C programming language
 The typical Unix commands that would be entered from the command
line
Unit 2   introduction to c programming
#include <stdio.h>
int main (void)
{
int v1, v2, sum;
//v1,v2,sum are variables and int is data type declared
v1 = 150;
v2 = 25;
sum = v1 + v2;
printf ("The sum of %i and %i is= %in", v1, v2, sum);
return 0;
}
Output: The sum of 150 and 25 is=175
 Every programming language has its own character set to form the
lexical elements.
 C Language Character Sets are:
 Alphabets
 Digits
 Special Characters
Unit 2   introduction to c programming
 The basic and smallest units of C program are called
C tokens.
 Keywords
 Identifiers
 Constants
 Strings
 Operators
 Special Symbols
 There are certain words reserved for doing specific task, these words
are known as reserved word or keywords.
 These words are predefined and always written in lower case or
small letter.
 These keywords can’t be used as a variable name as it assigned with
fixed meaning.
Example
 Identifiers are user defined word used to name of entities like
variables, arrays, functions, structures etc.
 Rules for naming identifiers are:
1) name should only consists of alphabets (both upper and lower case), digits
and underscore (_) sign.
2) first characters should be alphabet or underscore
3) name should not be a keyword
4) since C is a case sensitive, the upper case and lower case considered
differently, for example code, Code, CODE etc. are different identifiers.
5) identifiers are generally given in some meaningful name such as value,
net_salary, age, data etc.
 Constant is a any value that cannot be changed during program
execution.
 In C, any number, single character, or character string is known as a
constant.
 A constant is an entity that doesn’t change whereas a variable is an
entity that may change.
For example,
 Number 50 represents a constant integer value.
 The character string "Programming in C is fun.n" is an example of a constant
character string.
 C constants can be divided into two major categories:
 Primary Constants
 Secondary Constants
Unit 2   introduction to c programming
 Numeric constant
 Numeric constant consists of digits. It required minimum size of 2 bytes and max 4
bytes.
▪ Integer Constant
▪ Real Constant
 Character constant
 Character constant represented as a single character enclosed within a single quote.
 These can be single digit, single special symbol or white spaces such as ‘9’,’c’,’$’, ‘ ’
etc.
 String constant
 Set of characters are called string and when sequence of characters are enclosed
within a double quote.
 Some examples are “sarathina” , “908”, “3”,” ”, “A” etc.
 Symbolic constant
 Symbolic constant is a name that substitute for a sequence of characters and,
characters may be numeric, character or string constant.
 #define name value, #define MAX 10, #define CH ‘b’, #define NAME “sony”
 Variable is a data name which is used to store some data value or
symbolic names for storing program computations and results.
 The value of the variable can be changed during the execution.
 The rule for naming the variables is same as the naming identifier.
 Before used in the program it must be declared.
 Declaration of variables specify its name, data types and range of the
value that variables can store depends upon its data types.
Syntax:
int a;
char c;
float f;
 When we assign any initial value to variable during the declaration, is
called initialization of variables.
 When variable is declared but contain undefined value then it is
called garbage value.
 The variable is initialized with the assignment operator such as
Data type variable name = constant;
Example:
int a=20;
or
int a;
a=20;
 Data types refer to an extensive system used for declaring variables or
functions of different types before its use.
 The type of a variable determines how much space it occupies in
storage and how the bit pattern stored is interpreted.
 The value of a variable can be changed any time.
 C has the following 4 types of data types
 basic built-in data types: int, float, double, char
 Enumeration data type: enum
 Derived data type: pointer, array, structure, union
 Void data type: void
 A variable declared to be of type int can be used to contain integral
values only
 That is, values that do not contain decimal places.
 A variable declared to be of type float can be used for storing
floating- point numbers (values containing decimal places).
 The double type is the same as type float, only with roughly twice the
precision.
 The char data type can be used to store a single character, such as the
letter a, the digit character 6, or a semicolon similarly
 A variable declared char can only store character type value.
 There are two types of type qualifier in c
 Size qualifier: short, long
 Sign qualifier: signed, unsigned
 When the qualifier unsigned is used the number is always positive,
and when signed is used number may be positive or negative.
 If the sign qualifier is not mentioned, then by default sign qualifier is assumed.
 The range of values for signed data types is less than that of unsigned
data type.
 Because in signed type, the left most bit is used to represent sign,
while in unsigned type this bit is also used to represent the value.
Unit 2   introduction to c programming
C O M P L E T E D

More Related Content

PPTX
Operators and expressions
PPTX
Variables in C++, data types in c++
PPTX
Operators and expressions in c language
PPTX
Data Type in C Programming
PPTX
Variables in python
PPTX
Pointers in c language
PPTX
Functions in python
PDF
Python Decision Making
Operators and expressions
Variables in C++, data types in c++
Operators and expressions in c language
Data Type in C Programming
Variables in python
Pointers in c language
Functions in python
Python Decision Making

What's hot (20)

PPTX
Looping statements in C
PPT
Variables in C Programming
PPTX
Data types in python
PDF
C programming notes
PPSX
Algorithm and flowchart
PPTX
Presentation on C Switch Case Statements
PPTX
Data types in C
DOCX
Features of c language 1
PPTX
FLOW OF CONTROL-INTRO PYTHON
PDF
10. switch case
PPTX
PPTX
Data Types, Variables, and Operators
PDF
Python functions
PDF
Operators in python
PPT
PPTX
C and its errors
PPT
Introduction to Basic C programming 01
PPTX
Nesting of if else statement & Else If Ladder
PPTX
Data types
PPT
Decision making and loop in C#
Looping statements in C
Variables in C Programming
Data types in python
C programming notes
Algorithm and flowchart
Presentation on C Switch Case Statements
Data types in C
Features of c language 1
FLOW OF CONTROL-INTRO PYTHON
10. switch case
Data Types, Variables, and Operators
Python functions
Operators in python
C and its errors
Introduction to Basic C programming 01
Nesting of if else statement & Else If Ladder
Data types
Decision making and loop in C#
Ad

Similar to Unit 2 introduction to c programming (20)

PPTX
Introduction to C Unit 1
PDF
C programming language tutorial for beginers.pdf
PPTX
C Programming Unit-1
PPTX
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
PPTX
C programming Training in Ambala ! Batra Computer Centre
DOCX
C notes
PPTX
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
PPT
C Lang notes.ppt
PPTX
C lang7age programming powerpoint presentation
DOCX
C programming language Reference Note
PPT
Chapter3
PPTX
C Programming UNIT 1.pptx
PPSX
C basics 4 std11(GujBoard)
PDF
C programming introduction for beginners.pdf
PPTX
C language ppt
PPT
history of c.ppt
DOC
1. introduction to computer
PDF
C programming course material
PPT
490450755-Chapter-2.ppt
PPT
490450755-Chapter-2.ppt
Introduction to C Unit 1
C programming language tutorial for beginers.pdf
C Programming Unit-1
UNIT 5 C PROGRAMMING, PROGRAM STRUCTURE
C programming Training in Ambala ! Batra Computer Centre
C notes
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
C Lang notes.ppt
C lang7age programming powerpoint presentation
C programming language Reference Note
Chapter3
C Programming UNIT 1.pptx
C basics 4 std11(GujBoard)
C programming introduction for beginners.pdf
C language ppt
history of c.ppt
1. introduction to computer
C programming course material
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
Ad

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
master seminar digital applications in india
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Insiders guide to clinical Medicine.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
RMMM.pdf make it easy to upload and study
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Basic Mud Logging Guide for educational purpose
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
master seminar digital applications in india
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
01-Introduction-to-Information-Management.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Insiders guide to clinical Medicine.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Final Presentation General Medicine 03-08-2024.pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
RMMM.pdf make it easy to upload and study
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Basic Mud Logging Guide for educational purpose

Unit 2 introduction to c programming

  • 1. Unit - 2 Mithun D’Souza Assistant Professor, Department of Computer Science, PES Institute of Advanced Management Studies, Shivamogga
  • 2.  C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs.  C was originally first implemented on the DEC PDP-11 computer in 1972.  In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available description of C, now known as the K&R standard.  The UNIX operating system, the C compiler, and essentially all UNIX application programs have been written in C.
  • 3.  In 1988, the American National Standards Institute (ANSI) had formalized the C language.  C was invented to write UNIX operating system.  C is a successor of 'Basic Combined Programming Language' (BCPL) called B language.  Linux OS, PHP, and MySQL are written in C.  C has been written in assembly language
  • 5.  C has now become a widely used professional language for various reasons:  Easy to learn  Structured language  It produces efficient programs  It can handle low-level activities  It can be compiled on a variety of computer platforms
  • 6.  C was invented to write an operating system called UNIX.  C is a successor of B language which was introduced around the early 1970s.  The language was formalized in 1988 by the American National Standard Institute (ANSI).  The UNIX OS was totally written in C.  Today C is the most widely used and popular System Programming Language.  Most of the state-of-the-art software have been implemented using C.  Today's most popular Linux OS and RDBMS MySQL have been written in C.
  • 7.  C was initially used for system development work, particularly the programs that make-up the operating system.  C was adopted as a system development language because it produces code that runs nearly as fast as the code written in assembly language.  Operating Systems  Language Compilers  Assemblers  Text Editors  Print Spoolers  Network Drivers  Modern Programs  Databases  Language Interpreters  Utilities
  • 9.  In C, compiler is a special tool that compiles the program and converts it into the object file which is machine readable.  After the compilation process, the linker will combine different object files and creates a single executable file to run the program.
  • 10.  General purpose Programming Language  Structured Programming Language  Helps in the development of System Software  Rich set of Operators  Provides compact representation for expressions  Allows manipulation of internal processor registers  No rigid format: Any Number of statement can be typed in a single line  Portability: any C program can be run on different machines with little or no modification  Supports a rich set of data types  Very less number of reserved words  Pointer arithmetic and pointer manipulation  Ability to extend itself by adding functions to its library
  • 12.  System Software  Operating systems  Compilers  Assemblers  Editors  Loaders  Linkers  Application Software  Database Management Systems (DBMS)  Graphics Packages  Spread sheets  CAD/CAM applications  Word Processors  Office Automation Tools  Scientific and Engineering applications
  • 13. 1) Comment line 2) Preprocessor directive 3) Global variable declaration 4) main function( ) { Local variables; Statements; } User defined function ( ) { // user defined instructions/ statements }
  • 15.  It indicates the purpose of the program. It is represented as /*……………………………..*/  Comment line is used for increasing the readability of the program.  It is useful in explaining the program and generally used for documentation.  It is enclosed within the decimeters.  Comment line can be single or multiple line but should not be nested.  It can be anywhere in the program except inside string constant & character constant.
  • 16.  #include<stdio.h> tells the compiler to include information about the standard input/output library.  It is also used in symbolic constant such as #define PI 3.14(value).  The stdio.h (standard input output header file)  contains definition &declaration of system defined function such as  printf( ) - Printing on screen  scanf( ) - Reading data from user  pow( ) etc.  Generally printf() function used to display and scanf() function used to read value
  • 18.  This is the section where variable are declared globally  It can be access by all the functions used in the program.  And it is generally declared outside the function
  • 19.  It is the user defined function and every function has one main() function from where actually program is started and it is encloses within the pair of curly braces.  The main( ) function can be anywhere in the program but in general practice it is placed in the first position. Syntax : main() { …….. …….. …….. }
  • 20.  The main( ) function return value when it declared by data type as int main( ) { return 0 }  The main function does not return any value when void (means null/empty) as void main(void ) or void main() { printf (“C language”); } Output: C language
  • 21.  The program execution start with opening braces and end with closing brace.  And in between the two braces declaration part as well as executable part is mentioned.  And at the end of each line, the semi-colon is given which indicates statement termination. /*First c program with return statement*/ #include <stdio.h> int main (void) { printf ("welcome to c Programming language.n"); return 0; } Output: welcome to c programming language.
  • 22.  A compiler is a software program that analyzes a program developed in a particular computer language and then translates it into a form that is suitable for execution on a particular computer system.  The steps involves  entering,  compiling, and  executing a computer program  Which are developed in the C programming language  The typical Unix commands that would be entered from the command line
  • 24. #include <stdio.h> int main (void) { int v1, v2, sum; //v1,v2,sum are variables and int is data type declared v1 = 150; v2 = 25; sum = v1 + v2; printf ("The sum of %i and %i is= %in", v1, v2, sum); return 0; } Output: The sum of 150 and 25 is=175
  • 25.  Every programming language has its own character set to form the lexical elements.  C Language Character Sets are:  Alphabets  Digits  Special Characters
  • 27.  The basic and smallest units of C program are called C tokens.  Keywords  Identifiers  Constants  Strings  Operators  Special Symbols
  • 28.  There are certain words reserved for doing specific task, these words are known as reserved word or keywords.  These words are predefined and always written in lower case or small letter.  These keywords can’t be used as a variable name as it assigned with fixed meaning. Example
  • 29.  Identifiers are user defined word used to name of entities like variables, arrays, functions, structures etc.  Rules for naming identifiers are: 1) name should only consists of alphabets (both upper and lower case), digits and underscore (_) sign. 2) first characters should be alphabet or underscore 3) name should not be a keyword 4) since C is a case sensitive, the upper case and lower case considered differently, for example code, Code, CODE etc. are different identifiers. 5) identifiers are generally given in some meaningful name such as value, net_salary, age, data etc.
  • 30.  Constant is a any value that cannot be changed during program execution.  In C, any number, single character, or character string is known as a constant.  A constant is an entity that doesn’t change whereas a variable is an entity that may change. For example,  Number 50 represents a constant integer value.  The character string "Programming in C is fun.n" is an example of a constant character string.  C constants can be divided into two major categories:  Primary Constants  Secondary Constants
  • 32.  Numeric constant  Numeric constant consists of digits. It required minimum size of 2 bytes and max 4 bytes. ▪ Integer Constant ▪ Real Constant  Character constant  Character constant represented as a single character enclosed within a single quote.  These can be single digit, single special symbol or white spaces such as ‘9’,’c’,’$’, ‘ ’ etc.  String constant  Set of characters are called string and when sequence of characters are enclosed within a double quote.  Some examples are “sarathina” , “908”, “3”,” ”, “A” etc.  Symbolic constant  Symbolic constant is a name that substitute for a sequence of characters and, characters may be numeric, character or string constant.  #define name value, #define MAX 10, #define CH ‘b’, #define NAME “sony”
  • 33.  Variable is a data name which is used to store some data value or symbolic names for storing program computations and results.  The value of the variable can be changed during the execution.  The rule for naming the variables is same as the naming identifier.  Before used in the program it must be declared.  Declaration of variables specify its name, data types and range of the value that variables can store depends upon its data types. Syntax: int a; char c; float f;
  • 34.  When we assign any initial value to variable during the declaration, is called initialization of variables.  When variable is declared but contain undefined value then it is called garbage value.  The variable is initialized with the assignment operator such as Data type variable name = constant; Example: int a=20; or int a; a=20;
  • 35.  Data types refer to an extensive system used for declaring variables or functions of different types before its use.  The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.  The value of a variable can be changed any time.  C has the following 4 types of data types  basic built-in data types: int, float, double, char  Enumeration data type: enum  Derived data type: pointer, array, structure, union  Void data type: void
  • 36.  A variable declared to be of type int can be used to contain integral values only  That is, values that do not contain decimal places.  A variable declared to be of type float can be used for storing floating- point numbers (values containing decimal places).  The double type is the same as type float, only with roughly twice the precision.  The char data type can be used to store a single character, such as the letter a, the digit character 6, or a semicolon similarly  A variable declared char can only store character type value.
  • 37.  There are two types of type qualifier in c  Size qualifier: short, long  Sign qualifier: signed, unsigned  When the qualifier unsigned is used the number is always positive, and when signed is used number may be positive or negative.  If the sign qualifier is not mentioned, then by default sign qualifier is assumed.  The range of values for signed data types is less than that of unsigned data type.  Because in signed type, the left most bit is used to represent sign, while in unsigned type this bit is also used to represent the value.
  • 39. C O M P L E T E D