Basics of Programming
Language – ‘C’
 Introduction to C Language
 C is a general-purpose, structured, procedural
programming language developed by Dennis Ritchie (1972)
at Bell Laboratories.
 It is widely used for system software, embedded systems,
operating systems, and compiler development due to its
efficiency, portability, and low-level memory access.
 Why Learn C Language?
 Forms the foundation of many modern languages like C+
+, Java.
 Helps understand memory management and hardware
interaction.
 Simple syntax and powerful features.
 Features of C Language
 Simple and efficient
 Structured programming
 Portable (machine independent)
 Rich set of operators
 Supports low-level programming
 Fast execution speed
 Applications of C Language
 Operating systems
 Embedded systems
 Compilers and interpreters
 Device drivers
 Database systems
 Scientific and engineering applications
 Getting Started with C
 C programs are written using a text editor, compiled using
a C compiler (e.g., GCC), and executed as machine code.
 C follows a structured programming approach, dividing
programs into functions for better modularity and
readability.
 The C Character Set
The C character set includes:
 Alphabets: A–Z, a–z
 Digits: 0–9
 Special Characters: + - * / % = < > ( ) { } [ ] ; , . _ #
 White Spaces: space, tab, newline
 Constants, Variables, and Keywords
 Constant: A fixed value that does not change during
program execution
 Variable: A named memory location whose value can
change
 Keyword: Reserved words with predefined meaning in C
 Types of C Constants
1. Integer Constants – e.g., 10, -25, 0
2. Real (Floating) Constants – e.g., 3.14, -0.005
3. Character Constants – e.g., 'A', '9', 'n'
 Rules for Constructing Integer Constants
 Must contain at least one digit
 No decimal point allowed
 Can be positive or negative
 No spaces or commas
 Examples: 25, -100, 0
 Rules for Constructing Real Constants
 Must contain a decimal point
 Can be positive or negative
 No spaces allowed
 Examples: 3.14, -0.25, 10.0
 Rules for Constructing Character Constants
 Enclosed in single quotes
 Contains only one character
 Examples: 'A', '5', 'n'
 Types of C Variables
Based on data types:
 int – integer variables
 float – decimal values
 double – high-precision decimals
 char – character data
 Rules for Constructing Variable Names
 Must start with an alphabet or underscore
 Can contain alphabets, digits, and underscore
 Cannot use keywords
 No special symbols or spaces
 Case-sensitive
Examples: total, _sum, count1
 C Keywords
 C has 32 reserved keywords, such as:
int, float, char, if, else, for, while, return, break, continue,
void
 Keywords cannot be used as variable names.
 Structure of a C Program
A C program is divided into different sections:
1. Documentation section
2. Link section
3. Definition section
4. Global declaration section
5. main() function
6. User-defined functions
 Input and Output in C
 Input and output are performed using standard functions.
 Commonly used functions:
• scanf() – for input
• printf() – for output
 Receiving Input
 C uses scanf() to take input from the user.
 scanf("%d", &x);
 & is the address operator
 Format specifiers define data type
 C Instructions
 C programs consist of instructions that perform actions.
Type Declaration Instruction
Used to declare variables before use.
 int a;
 float b;
 Arithmetic Instruction
Used to perform mathematical operations.
c = a + b * d;
Operators: + - * / %
 Hierarchy of Operations
Operator precedence in C:
1. * / %
2. + -
3. =
Parentheses override precedence.
[A] Point out the errors, if any, in the following C statements:
(a) int = 314.562 * 150 ;
(b) name = ‘Ajay’ ;
(c) varchar = ‘3’ ;
(d) 3.14 * r * r * h = vol_of_cyl ;
(e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
[B] Evaluate the following expressions and show
their hierarchy.
(a) g = big / 2 + big * 4 / big - big + abc / 3 ; (abc = 2.5,
big = 2, assume g to be a float)
(b) on = ink * act / 2 + 3 / 2 * act + 2 + tig ; (ink = 4, act = 1,
tig = 3.2, assume on to be an int)
(c) s = qui * add / 4 - 6 / 2 + 2 / 3 * 6 / god ; (qui = 4,
add = 2, god = 2, assume s to be an int)
 What would be the output of the following programs:
(1) main( )
{
int i = 2, j = 3, k, l ;
float a, b ;
k = i / j * j ;
l = j / i * i ;
a = i / j * j ;
b = j / i * i ;
printf( "%d %d %f %f", k, l, a, b ) ; }
(2) main( )
{
float a = 5, b = 2 ;
int c ;
c = a % b ;
printf ( "%d", c ) ;
}

cONDITIONAL STATEMENT IN C PROGRAMMING IF ELSE

  • 2.
  • 3.
     Introduction toC Language  C is a general-purpose, structured, procedural programming language developed by Dennis Ritchie (1972) at Bell Laboratories.  It is widely used for system software, embedded systems, operating systems, and compiler development due to its efficiency, portability, and low-level memory access.
  • 4.
     Why LearnC Language?  Forms the foundation of many modern languages like C+ +, Java.  Helps understand memory management and hardware interaction.  Simple syntax and powerful features.
  • 5.
     Features ofC Language  Simple and efficient  Structured programming  Portable (machine independent)  Rich set of operators  Supports low-level programming  Fast execution speed
  • 6.
     Applications ofC Language  Operating systems  Embedded systems  Compilers and interpreters  Device drivers  Database systems  Scientific and engineering applications
  • 7.
     Getting Startedwith C  C programs are written using a text editor, compiled using a C compiler (e.g., GCC), and executed as machine code.  C follows a structured programming approach, dividing programs into functions for better modularity and readability.
  • 8.
     The CCharacter Set The C character set includes:  Alphabets: A–Z, a–z  Digits: 0–9  Special Characters: + - * / % = < > ( ) { } [ ] ; , . _ #  White Spaces: space, tab, newline
  • 9.
     Constants, Variables,and Keywords  Constant: A fixed value that does not change during program execution  Variable: A named memory location whose value can change  Keyword: Reserved words with predefined meaning in C
  • 10.
     Types ofC Constants 1. Integer Constants – e.g., 10, -25, 0 2. Real (Floating) Constants – e.g., 3.14, -0.005 3. Character Constants – e.g., 'A', '9', 'n'
  • 11.
     Rules forConstructing Integer Constants  Must contain at least one digit  No decimal point allowed  Can be positive or negative  No spaces or commas  Examples: 25, -100, 0
  • 12.
     Rules forConstructing Real Constants  Must contain a decimal point  Can be positive or negative  No spaces allowed  Examples: 3.14, -0.25, 10.0
  • 13.
     Rules forConstructing Character Constants  Enclosed in single quotes  Contains only one character  Examples: 'A', '5', 'n'
  • 14.
     Types ofC Variables Based on data types:  int – integer variables  float – decimal values  double – high-precision decimals  char – character data
  • 15.
     Rules forConstructing Variable Names  Must start with an alphabet or underscore  Can contain alphabets, digits, and underscore  Cannot use keywords  No special symbols or spaces  Case-sensitive Examples: total, _sum, count1
  • 16.
     C Keywords C has 32 reserved keywords, such as: int, float, char, if, else, for, while, return, break, continue, void  Keywords cannot be used as variable names.
  • 17.
     Structure ofa C Program A C program is divided into different sections: 1. Documentation section 2. Link section 3. Definition section 4. Global declaration section 5. main() function 6. User-defined functions
  • 20.
     Input andOutput in C  Input and output are performed using standard functions.  Commonly used functions: • scanf() – for input • printf() – for output
  • 21.
     Receiving Input C uses scanf() to take input from the user.  scanf("%d", &x);  & is the address operator  Format specifiers define data type
  • 22.
     C Instructions C programs consist of instructions that perform actions. Type Declaration Instruction Used to declare variables before use.  int a;  float b;
  • 23.
     Arithmetic Instruction Usedto perform mathematical operations. c = a + b * d; Operators: + - * / %
  • 24.
     Hierarchy ofOperations Operator precedence in C: 1. * / % 2. + - 3. = Parentheses override precedence.
  • 25.
    [A] Point outthe errors, if any, in the following C statements: (a) int = 314.562 * 150 ; (b) name = ‘Ajay’ ; (c) varchar = ‘3’ ; (d) 3.14 * r * r * h = vol_of_cyl ; (e) k = ( a * b ) ( c + ( 2.5a + b ) ( d + e ) ;
  • 26.
    [B] Evaluate thefollowing expressions and show their hierarchy. (a) g = big / 2 + big * 4 / big - big + abc / 3 ; (abc = 2.5, big = 2, assume g to be a float)
  • 27.
    (b) on =ink * act / 2 + 3 / 2 * act + 2 + tig ; (ink = 4, act = 1, tig = 3.2, assume on to be an int)
  • 28.
    (c) s =qui * add / 4 - 6 / 2 + 2 / 3 * 6 / god ; (qui = 4, add = 2, god = 2, assume s to be an int)
  • 29.
     What wouldbe the output of the following programs: (1) main( ) { int i = 2, j = 3, k, l ; float a, b ; k = i / j * j ; l = j / i * i ; a = i / j * j ; b = j / i * i ; printf( "%d %d %f %f", k, l, a, b ) ; }
  • 30.
    (2) main( ) { floata = 5, b = 2 ; int c ; c = a % b ; printf ( "%d", c ) ; }