際際滷

際際滷Share a Scribd company logo
Basics of C Programming
 The name C: C was an offspring of BCPL (Basic Combined Programming
Language) called B. Dennis Ritchie modified it and the new language was
named C.
 Importance of C
 Rich set of built in functions and operators  can be used to write any complex
program.
 The C compiler combines the capabilities of an assembly language with the features of
a high level language  well suited for writing system software and business packages.
 Programs written in C are efficient and fast due to variety of data types and powerful
operators.
 Less number of keywords- 32 only
 Highly portable  can be transferred from machine to machine with very little or no
modifications. It is important when we plan to use a new computer with a different
operating system.
 Well suited for structured programming  Program can be divided into modules.
 Modular structure makes debugging, testing and maintenance easy.
 Ability to extend itself  A C program is a collection of functions
supported by C Library.
 We can add our own functions to the C library.
 With the addition of large number of functions the programming task
becomes simpler
Process of compiling and running a C program
 The C Character set
 A character set denotes any alphabet, digit or special symbol which
are the basic building blocks used to form program elements
(variables, constants, operators)
 The characters in C fall into the following groups
 1. Letters: Upper case AZ, Lower case az
 2. Digits: All decimal digits 0.9
3. Special characters
Symbol Name
% Percent sign
# Number sign
& ampersand
^ caret
* asterisk
- minus
+ Plus
< Less than or opening
angle bracket
> Greater than or closing
angle bracket
( Left parenthesis
) Right parenthesis
[ Left bracket
] Right bracket
{ Left brace
} Right brace
!= Not equal to
Symbol Name
, comma
. period
; Semi colon
: colon
? Question
mark
 apostrophe
 quotation
mark
! exclamation
mark
| vertical bar
/ slash
 back slash
~ tilde
_ underscore
$ Dollar sign
 4. White spaces
 Blank space
 Horizontal tab
 Carriage return
 New line
 Form feed
 The compiler ignores white spaces unless they are part of a string constant.
 White spaces may be used to separate words, but are prohibited between
the characters of key words and identifiers
 ANSI C trigraph sequences
 Non-English keyboards may not have all the special characters. To enter certain
characters C provides 3 character trigraphs- 2 question marks followed by another
character
 For example # has the trigraph sequence ??+
 C tokens
 The smallest individual units in a C program are known as C tokens
 C has 6 types of tokens
 C programs are written using these tokens and the syntax of the
language
 C token are
 Keywords
 Identifiers
 Constants
 Strings
 Special symbols
 Operators
 Keywords
 Every C word is classified as a keyword or an identifier.
 Keywords:
 Keywords are reserved words that have fixed pre-defined meanings in C.
 These meanings cannot be changed.
 Keywords serve as basic building blocks for program statements.
 All keywords must be written in lower case
1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx
 Identifiers
 Identifiers are user defined names given to various program elements
such as variables, functions, arrays etc.
 The identifiers consists of a sequence of letters and digits with a letter
as the first character
 Both uppercase and lower case letters are permitted
 Lower case letters are commonly used
 The underscore character is also permitted in identifiers
 C distinguishes between lowercase and uppercase characters
 Valid identifiers : xy, x2y, tax_rate, _temp
 Invalid: 4th, X, order-no, error flag
 These are the fundamental requirement of any language.
 Each language has its own rules for naming these identifiers
 Only alphabetic characters, digits and underscores are permitted.
 The name cannot start with a digit.
 Uppercase and lowercase letters are distinct.
 A declared keyword cannot be used as a variable name.
 Constants in C++
 Constants refer to fixed values that do not change during the
execution of a program.
 They include integers, characters, floating point numbers and strings.
 Two types
 Numeric constants and character constants
 Numeric constants
 Integer and Real constants
 Character constants
 Single character constants, string constants
 Rules for Numeric Type Constants
 1. Commas and blank spaces cannot be included within the constant
 2. The constant can be preceded by a + or - sign
 3. The value of constant cannot exceed certain specified minimum
and maximum bounds
 Integer constants  An integer constant refers to a sequence of digits.
 They are whole numbers
 Integer constants can be written in three different number systems
 Decimal constants base 10
 Octal constants  base 8
 Hexadecimal constants  base 16
 Decimal integers consist of a set of digits 09 preceded by an
optional + or  sign
 If the constant contains 2 or more digits, then the first digit should not
be zero
 Valid decimal constants : 123, -321, 0, 6541, +78
 Invalid
 15 750 (blank space)
 20,000 (comma)
 36.0 (period)
 0900 (first digit should not be zero)
 Octal integer (base8)
 An octal integer constant can consist of any combination digits taken
from the set 0 through 7 with first digit 0.
 It can have + or  sign
 Valid: 012, -0467, +04013, 0, 01
 Invalid: 743 (not starting with 0)
 0482 (illegal digit 8)
 04.17 (decimal point-illegal character)
 Hexadecimal integer(base16)
 A hexadecimal integer constant is a sequence of digits preceded by 0X
 It can be followed by digits 0 through 9 and letters A through F
 Valid : 0X2, 0X9F, oXbcd, 0X
 Real constants (Floating point constants)
 Integer numbers are inadequate to represent quantities that vary
continuously such as distances, heights, temperatures, prices and so on.
 These quantities are represented by numbers containing a fractional part or
real numbers.
 Such numbers are real or floating point constants.
 They can be decimal notation or exponential notation.
 Eg.:0, 0.0083, -0.75, 12.3, 0.95 etc
 General form for exponential notation is
 Mantissa e Exponent
 215.65 may be written as 2.1565e2
 The mantissa may be either a real number or integer
 The exponent is an integer with optional + or  sign
 E separating mantissa and exponent can be written in either lower or upper case
 Valid  0.65e4, 12e-2, 1.5e+5, 3.18E3, -1.2E-1
 Invalid  7.1e 4, 1.51E+2.5, $255.0, 1
 Valid: 152E08, 152.0E8, 152E+8, 152E+08, 15.2e9, 1520e7
 Character constants
 Single character constants
 A single character constant or simply character constant is a single
character enclosed within a pair of single quote marks.
 Eg. 5, X,
 Character constants have integer values known as ASCII values.
 The character constant 3 and integer value 3 are not the same.
 ASCII- American Standard Code for Information Interchange
 Since each character constant represents an integer value, it is also
possible to perform arithmetic operations on character constants.
 String constants
 A string constant consists of any number of consecutive characters
(letters, numbers, special characters, and blank spaces) enclosed in
double quotes.
 Eg. Hello, GEC Thrissur, Knowledge is power, ?......!, 5+3,
  , X
 It is to be noted that X and X are different.
 X have an integer value where as X do not have an integer value
 String constants are used to make meaningful programs.
 Backslash character constants
 The backslash character constants are used in output functions. These character
combinations are also known as escape sequences
 a  audible alert
 b - backspace
 f- form feed
 n- new line
 r- carriage return
 t- horizontal tab
 v- vertical tab
   single quote
   double quote
 ?  question mark
  - backslash
 0 - null
 Variables
 A variable is a data name used to store a data value.
 A variable takes different values at different times during the program.
 It is an identifier that is used to represent some specified type of
information within a designated portion of the program.
 In its simplest form a variable represents a single data item that is a
numerical quantity or a character constant.
 The data item is assigned to the variable in some point in the program.
 The data item can be the accessed later in the program by simply referring
to the variable name.
 The information associated with the variable may change but the datatype
associated with the variable cannot change.
 A variable name shall be chosen in a meaningful way.
 A variable name can consist of letters, digits and underscore.
 1. They must begin with a letter. Some systems permit underscore as
a first character.
 2. ANSI standard recognizes a variable name length of 31 characters,
but the first 8 characters only are treated as significant. So it is better
to use meaningful names with 8 characters
 3. Uppercase and lowercase are significant.
 4. Variable name should not be a keyword.
 5. Whitespace is not allowed.
 Examples of valid variable names: mark, value, sum1, ph_value
 Examples of invalid variable names: char, 123, price$

More Related Content

Similar to 1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx (20)

PPTX
Introduction to C language programming.pptx
OVIDMAMAH
PPT
C presentation book
krunal1210
PPSX
Programming in c
vineet4523
PPT
C the basic concepts
Abhinav Vatsa
PDF
Introduction of c_language
SINGH PROJECTS
PPT
Computer Programming- Lecture 3
Dr. Md. Shohel Sayeed
PDF
C basics
Learn By Watch
PPT
All C ppt.ppt
JeelBhanderi4
PPT
Session02 c intro
HarithaRanasinghe
PPTX
datatypes and variables in c language
Rai University
PPTX
Btech i pic u-2 datatypes and variables in c language
Rai University
PPTX
Mca i pic u-2 datatypes and variables in c language
Rai University
PDF
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
PPTX
C introduction
AswathyBAnil
PPTX
Module 1:Introduction
nikshaikh786
PPTX
Diploma ii cfpc u-2 datatypes and variables in c language
Rai University
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
Rai University
PDF
Introduction to Computer and Programming - Lecture 03
hassaanciit
DOCX
C and DS -unit 1 -Artificial Intelligence and ML.docx
msurfudeen6681
PDF
Lecture 4 constants_variables
eShikshak
Introduction to C language programming.pptx
OVIDMAMAH
C presentation book
krunal1210
Programming in c
vineet4523
C the basic concepts
Abhinav Vatsa
Introduction of c_language
SINGH PROJECTS
Computer Programming- Lecture 3
Dr. Md. Shohel Sayeed
C basics
Learn By Watch
All C ppt.ppt
JeelBhanderi4
Session02 c intro
HarithaRanasinghe
datatypes and variables in c language
Rai University
Btech i pic u-2 datatypes and variables in c language
Rai University
Mca i pic u-2 datatypes and variables in c language
Rai University
Learning c - An extensive guide to learn the C Language
Abhishek Dwivedi
C introduction
AswathyBAnil
Module 1:Introduction
nikshaikh786
Diploma ii cfpc u-2 datatypes and variables in c language
Rai University
Bsc cs i pic u-2 datatypes and variables in c language
Rai University
Introduction to Computer and Programming - Lecture 03
hassaanciit
C and DS -unit 1 -Artificial Intelligence and ML.docx
msurfudeen6681
Lecture 4 constants_variables
eShikshak

Recently uploaded (20)

DOCX
Engineering Geology Field Report to Malekhu .docx
justprashant567
PPTX
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
PPTX
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
PPT
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
PDF
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
PDF
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
PDF
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
PPTX
Explore USAs Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
PDF
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
PDF
PRIZ Academy - Process functional modelling
PRIZ Guru
PDF
CLIP_Internals_and_Architecture.pdf sdvsdv sdv
JoseLuisCahuanaRamos3
PDF
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
PDF
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
PDF
惠惘惘 惺 悋惠忰 悋惆悋 惠惆 悋悋悄 忰 悴悋忰.pdf
忰惆 惶惶 惠惠悸
PDF
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
PDF
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
Engineering Geology Field Report to Malekhu .docx
justprashant567
Comparison of Flexible and Rigid Pavements in Bangladesh
Arifur Rahman
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
Kel.3_A_Review_on_Internet_of_Things_for_Defense_v3.pptx
Endang Saefullah
SF 9_Unit 1.ppt software engineering ppt
AmarrKannthh
June 2025 - Top 10 Read Articles in Network Security and Its Applications
IJNSA Journal
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
FSE-Journal-First-Automated code editing with search-generate-modify.pdf
cl144
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
Explore USAs Best Structural And Non Structural Steel Detailing
Silicon Engineering Consultants LLC
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
PRIZ Academy - Process functional modelling
PRIZ Guru
CLIP_Internals_and_Architecture.pdf sdvsdv sdv
JoseLuisCahuanaRamos3
Clustering Algorithms - Kmeans,Min ALgorithm
Sharmila Chidaravalli
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
惠惘惘 惺 悋惠忰 悋惆悋 惠惆 悋悋悄 忰 悴悋忰.pdf
忰惆 惶惶 惠惠悸
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
lesson4-occupationalsafetyandhealthohsstandards-240812020130-1a7246d0.pdf
arvingallosa3
Ad

1173_237_747_Module_2_Part1__Basics_of_C_programming__1_.pptx

  • 1. Basics of C Programming
  • 2. The name C: C was an offspring of BCPL (Basic Combined Programming Language) called B. Dennis Ritchie modified it and the new language was named C. Importance of C Rich set of built in functions and operators can be used to write any complex program. The C compiler combines the capabilities of an assembly language with the features of a high level language well suited for writing system software and business packages. Programs written in C are efficient and fast due to variety of data types and powerful operators. Less number of keywords- 32 only Highly portable can be transferred from machine to machine with very little or no modifications. It is important when we plan to use a new computer with a different operating system. Well suited for structured programming Program can be divided into modules. Modular structure makes debugging, testing and maintenance easy.
  • 3. Ability to extend itself A C program is a collection of functions supported by C Library. We can add our own functions to the C library. With the addition of large number of functions the programming task becomes simpler
  • 4. Process of compiling and running a C program
  • 5. The C Character set A character set denotes any alphabet, digit or special symbol which are the basic building blocks used to form program elements (variables, constants, operators) The characters in C fall into the following groups 1. Letters: Upper case AZ, Lower case az 2. Digits: All decimal digits 0.9 3. Special characters
  • 6. Symbol Name % Percent sign # Number sign & ampersand ^ caret * asterisk - minus + Plus < Less than or opening angle bracket > Greater than or closing angle bracket ( Left parenthesis ) Right parenthesis [ Left bracket ] Right bracket { Left brace } Right brace != Not equal to Symbol Name , comma . period ; Semi colon : colon ? Question mark apostrophe quotation mark ! exclamation mark | vertical bar / slash back slash ~ tilde _ underscore $ Dollar sign
  • 7. 4. White spaces Blank space Horizontal tab Carriage return New line Form feed The compiler ignores white spaces unless they are part of a string constant. White spaces may be used to separate words, but are prohibited between the characters of key words and identifiers ANSI C trigraph sequences Non-English keyboards may not have all the special characters. To enter certain characters C provides 3 character trigraphs- 2 question marks followed by another character For example # has the trigraph sequence ??+
  • 8. C tokens The smallest individual units in a C program are known as C tokens C has 6 types of tokens C programs are written using these tokens and the syntax of the language C token are Keywords Identifiers Constants Strings Special symbols Operators
  • 9. Keywords Every C word is classified as a keyword or an identifier. Keywords: Keywords are reserved words that have fixed pre-defined meanings in C. These meanings cannot be changed. Keywords serve as basic building blocks for program statements. All keywords must be written in lower case
  • 11. Identifiers Identifiers are user defined names given to various program elements such as variables, functions, arrays etc. The identifiers consists of a sequence of letters and digits with a letter as the first character Both uppercase and lower case letters are permitted Lower case letters are commonly used The underscore character is also permitted in identifiers C distinguishes between lowercase and uppercase characters Valid identifiers : xy, x2y, tax_rate, _temp Invalid: 4th, X, order-no, error flag
  • 12. These are the fundamental requirement of any language. Each language has its own rules for naming these identifiers Only alphabetic characters, digits and underscores are permitted. The name cannot start with a digit. Uppercase and lowercase letters are distinct. A declared keyword cannot be used as a variable name.
  • 13. Constants in C++ Constants refer to fixed values that do not change during the execution of a program. They include integers, characters, floating point numbers and strings. Two types Numeric constants and character constants Numeric constants Integer and Real constants Character constants Single character constants, string constants
  • 14. Rules for Numeric Type Constants 1. Commas and blank spaces cannot be included within the constant 2. The constant can be preceded by a + or - sign 3. The value of constant cannot exceed certain specified minimum and maximum bounds Integer constants An integer constant refers to a sequence of digits. They are whole numbers Integer constants can be written in three different number systems Decimal constants base 10 Octal constants base 8 Hexadecimal constants base 16
  • 15. Decimal integers consist of a set of digits 09 preceded by an optional + or sign If the constant contains 2 or more digits, then the first digit should not be zero Valid decimal constants : 123, -321, 0, 6541, +78 Invalid 15 750 (blank space) 20,000 (comma) 36.0 (period) 0900 (first digit should not be zero)
  • 16. Octal integer (base8) An octal integer constant can consist of any combination digits taken from the set 0 through 7 with first digit 0. It can have + or sign Valid: 012, -0467, +04013, 0, 01 Invalid: 743 (not starting with 0) 0482 (illegal digit 8) 04.17 (decimal point-illegal character) Hexadecimal integer(base16) A hexadecimal integer constant is a sequence of digits preceded by 0X It can be followed by digits 0 through 9 and letters A through F Valid : 0X2, 0X9F, oXbcd, 0X
  • 17. Real constants (Floating point constants) Integer numbers are inadequate to represent quantities that vary continuously such as distances, heights, temperatures, prices and so on. These quantities are represented by numbers containing a fractional part or real numbers. Such numbers are real or floating point constants. They can be decimal notation or exponential notation. Eg.:0, 0.0083, -0.75, 12.3, 0.95 etc General form for exponential notation is Mantissa e Exponent 215.65 may be written as 2.1565e2 The mantissa may be either a real number or integer The exponent is an integer with optional + or sign E separating mantissa and exponent can be written in either lower or upper case
  • 18. Valid 0.65e4, 12e-2, 1.5e+5, 3.18E3, -1.2E-1 Invalid 7.1e 4, 1.51E+2.5, $255.0, 1 Valid: 152E08, 152.0E8, 152E+8, 152E+08, 15.2e9, 1520e7 Character constants Single character constants A single character constant or simply character constant is a single character enclosed within a pair of single quote marks. Eg. 5, X, Character constants have integer values known as ASCII values. The character constant 3 and integer value 3 are not the same. ASCII- American Standard Code for Information Interchange Since each character constant represents an integer value, it is also possible to perform arithmetic operations on character constants.
  • 19. String constants A string constant consists of any number of consecutive characters (letters, numbers, special characters, and blank spaces) enclosed in double quotes. Eg. Hello, GEC Thrissur, Knowledge is power, ?......!, 5+3, , X It is to be noted that X and X are different. X have an integer value where as X do not have an integer value String constants are used to make meaningful programs.
  • 20. Backslash character constants The backslash character constants are used in output functions. These character combinations are also known as escape sequences a audible alert b - backspace f- form feed n- new line r- carriage return t- horizontal tab v- vertical tab single quote double quote ? question mark - backslash 0 - null
  • 21. Variables A variable is a data name used to store a data value. A variable takes different values at different times during the program. It is an identifier that is used to represent some specified type of information within a designated portion of the program. In its simplest form a variable represents a single data item that is a numerical quantity or a character constant. The data item is assigned to the variable in some point in the program. The data item can be the accessed later in the program by simply referring to the variable name. The information associated with the variable may change but the datatype associated with the variable cannot change. A variable name shall be chosen in a meaningful way. A variable name can consist of letters, digits and underscore.
  • 22. 1. They must begin with a letter. Some systems permit underscore as a first character. 2. ANSI standard recognizes a variable name length of 31 characters, but the first 8 characters only are treated as significant. So it is better to use meaningful names with 8 characters 3. Uppercase and lowercase are significant. 4. Variable name should not be a keyword. 5. Whitespace is not allowed. Examples of valid variable names: mark, value, sum1, ph_value Examples of invalid variable names: char, 123, price$