PROGRAMMING IN C
S.AARTHI
ASSISTANT PROFESSOR, DEPARTMENT OF INFORMATION TECHNOLOGY
INTRODUCTION
 C is a general-purpose programming language created by Dennis Ritchie at the Bell
Laboratories in 1972.
 It is a very popular language, despite being old. The main reason for its popularity is
because it is a fundamental language in the field of computer science.
 C is strongly associated with UNIX, as it was developed to write the UNIX operating
system.
Why Learn C?
• It is one of the most popular programming languages in the world
• If you know C, you will have no problem learning other popular programming
languages such as Java, Python, C++, C#, etc, as the syntax is similar
• If you know C, you will understand how computer memory works
• C is very fast, compared to other programming languages, like Java and Python
• C is very versatile; it can be used in both applications and technologies
C TOKENS
CONSTANTS,VARIABLES,& DATATYPES
CONSTANTS
 In C programming, const is a keyword used to declare a variable as constant,
meaning its value cannot be changed after it is initialized. It is mainly used to
protect variables from being accidentally modified, making the program safer
and easier to understand. These constants can be of various types, such as
integer, floating-point, string, or character constants.
#include <stdio.h>
int main() {
// Defining constant variable
const int a = 10;
printf("%d", a);
return 0;
}
variables
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords).
for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -
19.99
char - stores single characters, such as 'a' or 'B'. Characters are
surrounded by single quotes.
Declaring (Creating) Variables.
To create a variable, specify the type and assign it a value:
syntax:
type variableName = value;
DATATYPES
 Each variable in C has an associated data type. It specifies the type of data
that the variable can store like integer, character, floating, double, etc.
 C is a statically type language where each variable's type must be specified at
the declaration and once specified, it cannot be changed.
Integer Data Type
• Stores whole numbers (positive, negative, or zero).
• We use int keyword to declare the integer variable:
• Size: 4 bytes, Range: -2,147,483,648 to 2,147,483,647.
• Format specifier: %d
Character Data Type
• Stores a single character (like ‘A’, ‘b’, or ‘5’).
• Size: 1 byte, Range: -128 to 127 (signed by default).
• Format specifier: %c.
Float Data Type
• Stores decimal numbers (numbers with fractional part).
• Size: 4 bytes, Approximate range: 3.4e-38 to 3.4e+38.
• Format specifier: %
Double Data Type
• Stores decimal numbers with more precision than float.
• Size: 8 bytes, Approximate range: 1.7e-308 to 1.7e+308.
• Format specifier: %lf.
Void Data Type
• Represents no value or empty type.
• Used in functions that do not return any value.
• Can also be used for generic pointers (void *) in memory operations.
OPERATORS AND EXPRESSIONS
OPERATORS
 Operators are the basic components of C programming. They are symbols that
represent some kind of operation, such as mathematical, relational, bitwise,
conditional, or logical computations, which are to be performed on values or
variables. The values and variables used with operators are called operands.
Unary, Binary and Ternary Operators
On the basis of the number of operands they work on, operators can be classified into
three types :
1. Unary Operators: Operators that work on single operand.
Example: Increment( ++) , Decrement(--)
2. Binary Operators: Operators that work on two operands.
Example: Addition (+), Subtraction( -) , Multiplication (*)
3. Ternary Operators: Operators that work on three operands.
Example: Conditional Operator( ? : )
TYPES OF OPERATORS
 C language provides a wide range of built in operators that can be classified
into 6 types based on their functionality:
Arithmetic Operators
The arithmetic operators are used to perform arithmetic/mathematical
operations on operands. There are arithmetic operators in C language:
a+b, a-b , a*b , a/b , a%b.
Relational Operators
The relational operators in C are used for the comparison of the two
operands. All these operators are binary operators that return true or false
values as the result of comparison.
a<b , a>b , a<=b , a>=b , a==b, a =!b
Logical Operator
Logical Operators are used to combine two or more conditions/constraints
or to complement the evaluation of the original condition in consideration.
The result of the operation of a logical operator is a Boolean value either true
or false.
Symbol Operator Description Syntax
&& Logical AND
Returns true if both
the operands are
true.
a && b
|| Logical OR
Returns true if both or
any o f the operand
is true.
a || b
! Logical NOT
Returns true if the
operand is false.
!a
EXPRESSION
 An expression is a combination of operators, constants and variables. An
expression may consist of one or more operands, and zero or more
operators to produce a value.
Types of Expressions:
Expressions may be of the following types:
Constant expressions:
Constant Expressions consists of only constant values. A constant value is one
that doesn't change. Examples:
5, 10 + 5 / 6.0, 'x’
Integral expressions:
Integral Expressions are those which produce integer results after implementing
all the automatic and explicit type conversions. Examples:
x, x * y, x + int( 5.0)
where x and y are integer variables.
Floating expressions:
Float Expressions are which produce floating point results after implementing
all the automatic and explicit type conversions. Examples:
x + y, 10.75
where x and y are floating point variables.
Relational expressions:
Relational Expressions yield results of type bool which takes a value true
or false. When arithmetic expressions are used on either side of a relational
operator, they will be evaluated first and then the results compared. Relational
expressions are also known as Boolean expressions. Examples:
x <= y, x + y > 2
Logical expressions:
Logical Expressions combine two or more relational expressions and produces
bool type results. Examples:
x > y && x == 10, x == 10 || y == 5
Pointer expressions:
Pointer Expressions produce address values. Examples:
&x, ptr, ptr++
where x is a variable and ptr is a pointer.
Bitwise expressions:
Bitwise Expressions are used to manipulate data at bit level. They are basically
used for testing or shifting bits. Examples:
x << 3
shifts three bit position to left
y >> 1
shifts one bit position to right. Shift operators are often used for multiplication
and division by powers of two.
THANK YOU

PROGRAMMING IN C,constant-variable-datatypes,operator-expression.pptx

  • 1.
    PROGRAMMING IN C S.AARTHI ASSISTANTPROFESSOR, DEPARTMENT OF INFORMATION TECHNOLOGY
  • 2.
    INTRODUCTION  C isa general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.  It is a very popular language, despite being old. The main reason for its popularity is because it is a fundamental language in the field of computer science.  C is strongly associated with UNIX, as it was developed to write the UNIX operating system. Why Learn C? • It is one of the most popular programming languages in the world • If you know C, you will have no problem learning other popular programming languages such as Java, Python, C++, C#, etc, as the syntax is similar • If you know C, you will understand how computer memory works • C is very fast, compared to other programming languages, like Java and Python • C is very versatile; it can be used in both applications and technologies
  • 3.
  • 4.
    CONSTANTS,VARIABLES,& DATATYPES CONSTANTS  InC programming, const is a keyword used to declare a variable as constant, meaning its value cannot be changed after it is initialized. It is mainly used to protect variables from being accidentally modified, making the program safer and easier to understand. These constants can be of various types, such as integer, floating-point, string, or character constants. #include <stdio.h> int main() { // Defining constant variable const int a = 10; printf("%d", a); return 0; }
  • 5.
    variables Variables are containersfor storing data values, like numbers and characters. In C, there are different types of variables (defined with different keywords). for example: int - stores integers (whole numbers), without decimals, such as 123 or -123 float - stores floating point numbers, with decimals, such as 19.99 or - 19.99 char - stores single characters, such as 'a' or 'B'. Characters are surrounded by single quotes. Declaring (Creating) Variables. To create a variable, specify the type and assign it a value: syntax: type variableName = value;
  • 6.
    DATATYPES  Each variablein C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc.  C is a statically type language where each variable's type must be specified at the declaration and once specified, it cannot be changed. Integer Data Type • Stores whole numbers (positive, negative, or zero). • We use int keyword to declare the integer variable: • Size: 4 bytes, Range: -2,147,483,648 to 2,147,483,647. • Format specifier: %d Character Data Type • Stores a single character (like ‘A’, ‘b’, or ‘5’). • Size: 1 byte, Range: -128 to 127 (signed by default). • Format specifier: %c.
  • 7.
    Float Data Type •Stores decimal numbers (numbers with fractional part). • Size: 4 bytes, Approximate range: 3.4e-38 to 3.4e+38. • Format specifier: % Double Data Type • Stores decimal numbers with more precision than float. • Size: 8 bytes, Approximate range: 1.7e-308 to 1.7e+308. • Format specifier: %lf. Void Data Type • Represents no value or empty type. • Used in functions that do not return any value. • Can also be used for generic pointers (void *) in memory operations.
  • 8.
    OPERATORS AND EXPRESSIONS OPERATORS Operators are the basic components of C programming. They are symbols that represent some kind of operation, such as mathematical, relational, bitwise, conditional, or logical computations, which are to be performed on values or variables. The values and variables used with operators are called operands. Unary, Binary and Ternary Operators On the basis of the number of operands they work on, operators can be classified into three types : 1. Unary Operators: Operators that work on single operand. Example: Increment( ++) , Decrement(--) 2. Binary Operators: Operators that work on two operands. Example: Addition (+), Subtraction( -) , Multiplication (*) 3. Ternary Operators: Operators that work on three operands. Example: Conditional Operator( ? : )
  • 9.
    TYPES OF OPERATORS C language provides a wide range of built in operators that can be classified into 6 types based on their functionality: Arithmetic Operators The arithmetic operators are used to perform arithmetic/mathematical operations on operands. There are arithmetic operators in C language: a+b, a-b , a*b , a/b , a%b. Relational Operators The relational operators in C are used for the comparison of the two operands. All these operators are binary operators that return true or false values as the result of comparison. a<b , a>b , a<=b , a>=b , a==b, a =!b
  • 10.
    Logical Operator Logical Operatorsare used to combine two or more conditions/constraints or to complement the evaluation of the original condition in consideration. The result of the operation of a logical operator is a Boolean value either true or false. Symbol Operator Description Syntax && Logical AND Returns true if both the operands are true. a && b || Logical OR Returns true if both or any o f the operand is true. a || b ! Logical NOT Returns true if the operand is false. !a
  • 11.
    EXPRESSION  An expressionis a combination of operators, constants and variables. An expression may consist of one or more operands, and zero or more operators to produce a value.
  • 12.
    Types of Expressions: Expressionsmay be of the following types:
  • 13.
    Constant expressions: Constant Expressionsconsists of only constant values. A constant value is one that doesn't change. Examples: 5, 10 + 5 / 6.0, 'x’ Integral expressions: Integral Expressions are those which produce integer results after implementing all the automatic and explicit type conversions. Examples: x, x * y, x + int( 5.0) where x and y are integer variables. Floating expressions: Float Expressions are which produce floating point results after implementing all the automatic and explicit type conversions. Examples: x + y, 10.75 where x and y are floating point variables.
  • 14.
    Relational expressions: Relational Expressionsyield results of type bool which takes a value true or false. When arithmetic expressions are used on either side of a relational operator, they will be evaluated first and then the results compared. Relational expressions are also known as Boolean expressions. Examples: x <= y, x + y > 2 Logical expressions: Logical Expressions combine two or more relational expressions and produces bool type results. Examples: x > y && x == 10, x == 10 || y == 5 Pointer expressions: Pointer Expressions produce address values. Examples: &x, ptr, ptr++ where x is a variable and ptr is a pointer.
  • 15.
    Bitwise expressions: Bitwise Expressionsare used to manipulate data at bit level. They are basically used for testing or shifting bits. Examples: x << 3 shifts three bit position to left y >> 1 shifts one bit position to right. Shift operators are often used for multiplication and division by powers of two.
  • 16.