SlideShare a Scribd company logo
UNIT- 1
OVERVIEW OF C
1. History of C Language
⮚ The root of all modern language is ALGOL, introduced in the early 1960
⮚ ALGOL was developed by Corrado Bohm, it was the 1st
computer language
⮚ In 1967, Martin Richard developed a language called BCPL( Basic Combined Programming
Language)
⮚ In 1970, Ken Thompson, developed B language – it is an early version of UNIX operating system
⮚ In 1972, Dennis Ritchie was evolved a C language at Bell Laboratories
⮚ C is a programming language
⮚ It is a structured, high-level, machine independent language
⮚ It allows software developers to develop programs
⮚ C is running under a variety of operating system and hardware platforms
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Features of C Language
C is the widely used language. It provides
many features that are given below.
• Simple
• Machine Independent or Portable
• Mid-level programming language
• Structured programming language
• Rich Library
• Memory Management
• Fast Speed
• Pointers
• Recursion
• Extensible
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. IMPORTANCE OF C- PROGRAMMING
• C is called as a robust language, which has so many built-in functions and operations, which can be used to
write any complex program.
• C as a middle level language.
• The ‘C’ compiler combines the capabilities of an assembly language with the features of a high-level language.
• It is the best for writing both system software and business packages.
• ‘C’ Programs are efficient and fast.
• C is highly portable
• Because ‘C’ programs written on one computer can be run on another with little (or) no modification.
• ‘C’ language is best for structured programming, where the user can think of a problem in terms of
function modules (or) blocks.
• It has the ability to extend itself.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
3. Structure of C- Programming Language
❖Preprocessor Directives: Used to include libraries or header files.
❖Global Declarations: Optional variables or function prototypes that are available to all functions.
❖main() Function: The entry point for program execution.
❖Local Variables: Declared inside functions to hold temporary data.
❖ Statements and Expressions: Code that performs operations or computations.
❖ Return Statement: Indicates program termination and success.
❖Functions: Additional code modules that perform specific tasks, improving readability and reusability.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Basic Structure of a C Program
#include <stdio.h> // Preprocessor Directive
// Global Variable Declarations (if any)
// Function Prototypes (if any)
// Main Function
int main()
{
// Local Variable Declarations
// Code Statements
return 0; // Return statement
}
// Additional Functions (if any)
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
EXECUTING C- PROGRAM
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
1. Preprocessor Directives (#include and others)
∙ These are lines starting with #
∙ Processed before the compilation of the actual code.
∙ They allow for the inclusion of libraries or files that provide additional functionality.
Example:
✔#include <stdio.h>
- #include <stdio.h>: This includes the Standard Input Output (stdio) library that provides
functions for I/O operations like printf(), scanf(), etc.
✔#include <stdlib.h>
- #include <stdlib.h>: Includes the Standard Library for memory allocation, random number
generation, and other utility functions.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. Global Declarations (Optional)
∙ Global variables or function prototypes can be declared outside any function
∙ Usually before the main() function.
∙ Global variables can be accessed by any function in the program.
Example:
✔ int globalVariable = 10; // A global variable
3. The main() Function
∙ The main() function is the starting point of a C program.
∙ Every C program must have a main() function.
∙ It’s where the program execution begins.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Syntax:
int main( )
{
// Statements to be executed
return 0; // Indicates successful execution
}
❖Return Type: The main() function typically returns an integer (int), with 0 generally indicating successful
execution
❖Statements inside main(): This includes variable declarations, input/output operations, function calls, and
other logic.
Example :
int main( )
{
printf(“ HELLO”);
return 0;
}
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
4. Local Variable Declarations
✔Inside the main() function (or other functions), local variables are declared.
✔Local variables are used for storing data during the program’s execution and are only accessible within the function
they are declared in.
Example:
int x = 5; // Local variable declaration
char letter = 'A'; // Another local variable
5. Statements and Expressions
✔The statements inside the main() function define the program’s behavior.
✔This includes assignments, input/output, conditional statements, loops, etc.
Examples:
printf("Hello, World!n"); // Output statement
int y = x + 10; // Arithmetic expression
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
6. Return Statement
✔ return 0; is used to indicate the program has completed successfully.
✔ In the main() function, this is important because it signals the operating system that the program ended without errors.
✔ Other functions might return values that are used by the program.
7. Functions (Optional)
∙ C programs can have additional functions that are defined outside the main() function.
∙ These can be called from main() or other functions to break the code into smaller, manageable pieces.
Syntax of a function:
int add(int a, int b)
{
return a + b;
}
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
4. PROGRAMMING STYLE CONSTANTS,
VARIABLES AND DATA TYPES
Programming Style:
∙ Consistent indentation, meaningful variable names, and proper commenting improve code readability
Constants:
∙ #define is used for simple constants, while const allows type safety and better debugging
Variables:
∙ Declare variables with appropriate data types and initialize them properly
Data Types:
∙ Use the appropriate data type (int, float, double, char, etc.) based on the kind of data the variable will hold
∙ C provides both primitive (e.g., int, char) and derived data types (e.g., arrays, structures)
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
1. Programming Style in C
✔Programming style refers to the conventions and practices you follow while writing your code.
✔It ensures that the code is readable, maintainable, and understandable for both yourself and others.
✔Consistent style improves collaboration and debugging.
Key elements of programming style include:
1. Indentation and Formatting:
o Use consistent indentation to make the code easy to follow (e.g., 4 spaces or 1 tab per indentation
level).
o Code blocks (e.g., loops, functions) should be properly indented.
o Use blank lines to separate logical blocks of code.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Example: 1
if (x > 10)
{
printf("x is greater than 10n");
}
2. Meaningful Variable Names:
o
Choose descriptive names for variables, functions, and constants.
o
Use meaningful names that indicate the purpose of the variable (e.g., count, totalAmount, temperature).
Example:2
int number Of Students; // Descriptive variable name
o
Add comments to explain what your code is doing, especially for complex logic.
o
Use comments to clarify non-obvious sections of code.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
CONSTANTS, VARIBLES AND DATA TYPES
CHARACTER SET
• The character set in C is a collection of characters that the C language recognizes and uses to form words, expressions, and numbers:
• Alphabets: The 26 uppercase and 26 lowercase letters of the English alphabet
• Digits: The numerals 0–9
• Special characters: Symbols such as +, -, *, /, =, <, >, & , |, !, ^, ~, %, #, , ;, :, ', "
• Whitespace characters: Spaces, tabs, newlines, and form feeds
• Escape sequences: Characters with special meanings that are prefixed with a backslash, such as n (newline), t (tab),  (backslash
character), ' (single quote), and " (double quote)
TRIGRAPH CHARACTERS
- A trigraph is a sequence of three characters that is used to
represent punctuation characters.
- Trigraphs are used when a character set doesn't have
convenient graphic representations for some punctuation characters.
Examples of trigraph are
Trigraph Character
??/ —
??< {
??- ~
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
C TOKENS
• A token in C can be defined as the smallest individual element of the
C programming language that is meaningful to the compiler.
• It is the basic component of a C program.
• The tokens of C language can be classified into six types based on the
functions they are used to perform.
1. Keywords:
• The keywords are pre-defined or reserved words in a programming
language.
• Each keyword is meant to perform a specific function in a program.
• keywords are referred names for a compiler, they can’t be used as
variable names You cannot redefine keywords.
• C language supports 32 keywords which are given below:
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. Identifiers:
• Identifiers are used for naming of variables, functions, and arrays.
• Once declared, you can use the identifier in later program statements to refer to the associated value.
• A special identifier called a statement label can be used in goto statements.
Rules for Naming Identifiers
• Certain rules should be followed while naming c identifiers which are as follows:
• They must begin with a letter or underscore(_).
• They must consist of only letters, digits, or underscore. No other special character is allowed.
• It should not be a keyword.
• It must not contain white space.
• It should be up to 31 characters long as only the first 31 characters are significant.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
CONSTANTS
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Integer Constants
• Integer constants are sequences of integers with a fixed value.
• They must not contain any decimal points or fractional numbers.
• Integer constants can either be positive or negative numbers.
• They include decimal system integers, octal system integers, hexadecimal system integers.
1.Decimal integers – Set of digits ranging from 0 to 9. For Example – const int y = 123;
2.Octal integers – Set of digits ranging from 0 to 7 which start with the number ‘0’ in the beginning/at the
prefix. For example – const int x = 032;
3.Hexadecimal integers – Set of digits ranging from 0 to 9 and alphabets from A to F where A indicates
number 10 and F indicates number 15. 0x is used at the prefix of the value. For example – const int z =
0x14;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Real Constants or Floating-point Constants
• They contain fractional numbers that can be written in 2 forms, Fractional form, and Exponential form.
• Eg. 140.9, 4578.218, 4.1 e 45 (i.e. 4.1 * 10^45), 5.0 e -2 (i.e. 5.0 * 10^-2)
Character Constants
• Any single character from the defined character set is called a character constant.
• They include a single alphabet, single-digit, single symbol enclosed within single inverted commas.
• Eg. ‘A’, ‘p’, ‘4’, ‘$’, ‘=’
String Constants
• It contains a set/collection of characters that should be enclosed within double inverted commas.
• Eg. “Hello”, “Length”, “ND123”
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Backslash character constant
• A backslash (  ) that allows a visual representation of some nongraphic characters introduces an escape.
• One of the common escape constants is the newline character( ).
Examples:
haracter Meaning
‘a’ alert
‘b’ backspace
‘f’ form feed
’n’ newline
‘t’ horizontal tab
‘r’ carriage return
‘v’ vertical tab
‘’ backslash
‘’ ’ single quote
‘" ’ double quote
‘?’ Question mark
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
VARIABLES
• Variables are key building elements of the C programming language
• It is used to store and modify data in computer programs.
• A variable is a designated memory region that stores a specified data type value.
• Each variable has a unique identifier, its name, and a data type describing the type of data it may hold.
Syntax:
The syntax for defining a variable in C is as follows:
data_type variable _name ;
Rules:
• variable_name: It is the identifier for the variable, i.e., the name you give to the variable to access its value later in
the program.
• The variable name must follow specific rules, like starting with a letter or underscore and consisting of letters,
digits, and underscores.
• An example of declaring the variable is given below:
int a;
float b;
char c;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
DATA TYPES
• C language is rich in data types.
• 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.
• Each data type requires different amounts of memory and has some specific operations which can be
performed over it.
There are 3 types of data types:
1. Primary or fundamental data types- Primitive data types are the most basic data types that are used for
representing simple values such as integers, float, characters, etc. Example: int, char, float, double, void
2. Derived data types- The data types that are derived from the primitive or built-in datatypes are referred to
as Derived Data Types. Example: array, pointers, function
3. User-defined datatypes - The user-defined data types are defined by the user himself. Example :
structure, union, enum
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
1. Integer Types:
The integer datatype in C is used to store the integer numbers (any number including positive, negative and zero
without decimal part).
Octal values, hexadecimal values, and decimal values can be stored in int data type in C.
• Range: -2,147,483,648 to 2,147,483,647
• Size: 4 bytes
• Format Specifier: %d
Syntax of Integer:
int var_name;
Example:
int a; // Declaration
int a=10; // initialization
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
• The integer data type can also be used as
1.unsigned int: Unsigned int data type in C is used to store the data values from zero to positive numbers but it
can’t store negative values like signed int.
2.short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768 to 32,767.
3.long int: Larger version of the int datatype so can store values greater than int.
4.unsigned short int: Similar in relationship with short int as unsigned int with int.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. Floating Point Types:
• In C programming float data type is used to store floating-point values.
• Float in C is used to store decimal and exponential values.
• It is used to store decimal numbers (numbers with floating point values) with single precision.
• Range: 1.2E-38 to 3.4E+38
• Size: 4 bytes
• Format Specifier: %f
Syntax of float :
float var_name;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Example:
float a = 9.0f;
3. Void Data Type:
• The void data type in C is used to specify that no value is present.
• It does not provide a result value to its caller.
• It has no values and no operations.
• It is used to represent nothing.
• Void is used in multiple ways as function return type, function arguments as void, and pointers and void.
4. Character Type:
• Character data type allows its variable to store only a single character.
• The size of the character is 1 byte. It is the most basic data type in C.
• It stores a single character and requires a single byte of memory in almost all compilers.
• Range: (-128 to 127) or (0 to 255)
• Size: 1 byte .Format Specifier: %c
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Syntax of char
•The char keyword is used to declare the variable of character type:
char var_name;
Example:
char a = 'a';
char c;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Declaration Of Variables
• The declaration of the variable must be done before they are used in the program.
• Declaration of variables does two things:
1. It tells the compiler what the variable name is
2. It specifies what type of data the variable will hold.
Two types of Declaration:
3. Primary type declaration
4. User- Defined type declaration.
1. Primary Type Declaration:
A variable can be used to store a value of any data type.
Syntax:
data-type v1,v2,…., vn;
• V1, v2, v3,…,vn are the names of the variables.
• Variables are separated by commas.
• A declaration statement must end with a semicolon.
• Example: int count;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. User defined Type Declaration:
The data types defined by the user themself are referred to as user-defined data types.
These data types are derived from the existing datatypes.
Need of User-Defined Datatypes
• It enables customization in the code.
• Users can write more efficient and flexible code.
• Provides abstraction.
Types of User-Defined Data Types
1. Enumeration (enums)
• Enum is short for "Enumeration".
• It allows the user to create custom data types with a set of named integer constants.
• The "enum" keyword is used to declare an enumeration. Enum simplifies and makes the program more
readable.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Syntax:
enum enum_name {const1, const2, ..., const N};
•Here, the const1 will be assigned 0, const2 = 1, and so on in the sequence.
•We can also assign a custom integer value such as:
Example: 1
enum enum_name {
const1 = 8;
const2 = 4;
}
Example 2:
enum day { Monday , Tuesday,…, Sunday};
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. typedef
• typedef is used to redefine the existing data type names.
• It is used to provide new names to the existing data types.
• The "typedef" keyword is used for this purpose;
Syntax
typedef type identifier;
Example:
typedef int units;
typedef float marks;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
OPERATORS AND EXPRESSIONS
• Operators are special symbols in C that performs an operation on values and variables.
• These special symbols allow us to manipulate data and variables in different ways.
Those Operators are classified into the following
• Arithmetic operators.
• Relational operators.
• Logical operators.
• Assignment operators.
• Increment and decrement operators.
• Bitwise operators.
• Conditional operators.
• Special operators.
1. ARITHMETIC OPERATORS
• Arithmetic operators are used for numerical calculations (or) to perform arithmetic operations like addition,
subtraction etc.
• There are 3 types of arithmetic operators
1. Integer arithmetic
2. Real arithmetic
3. Mixed mode arithmetic
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Operator Description Example a=20,b=10 Output
+ Addition a+b 20+10 30
- subtraction a-b 20-10 10
* multiplication a*b 20*10 200
/ Division a/b 20/10 2(quotient)
% Modular Division a%b 20%10 0 (remainder)
Examples of Arithmetic operations
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Example code:
#include<stdio.h>
void main ()
{
int a= 20, b = 10;
printf (" %d", a+b);
printf (" %d", a-b);
printf (" %d", a*b);
printf (" %d", a/b);
printf (" %d", a%b);
}
Output
•30 10 200 20
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
1. Integer Arithmetic:
• when both the operands in a single arithmetic expressions such as a+b are integers, these expression
are called as integer expressions
• These operations are called integer arithmetic
• Integer arithmetic always yields an integer value
• The largest integer values depends on machine
• During Division, if both the operands are of same sign the result is truncated towards zero
• if one of them is negative , the direction of truncation is implementation dependent
Example: 6/7=0 and -6/-7=0 but -6/7 may be zero or -1(machine dependent)
• During Modulo division , the sign of the result is always the sign of the first operand
Example : -14 % 3= -2 or -14 % -3 = -2 or 14 % -3= 2
2. Real Arithmetic:
• An arithmetic operation involving only real operands is called real arithmetic
• A real operand may assume values either in decimal or exponential notation
• Since floating point values are rounded to the number of significant digits permissible
• The final value is an approximation of the correct result.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Example: If x ,y , z are floats then we will have
x= 6.0/7.0=0.857143
Y= 1.0/3.0 =0.333333
Z= -2.0/3.0= -0.66667
3.Mixed mode Arithmetic:
When one or more operands is real and the other is integer , the expression is called a mixed mode arithmetic
expressions.
If either operand is of real type, then only the real operation is performed, and the result is always a real number.
Example : 15/10.0= 1.5
Whereas 15/10=1
2. RELATIONAL OPERATORS
• Relational operators are used for comparing two expressions such as greater, lesser, equal, not equal.
• The operators used are < , <=, >, >= , = =, != .
• The output of a relational expression is either true (1) (or) false (0).
Syntax:
Expression 1 relational operator expression 2
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Operator Description Example a=20,b=10 Output
< less than a<b 10<20 1
<= less than (or) equal to a<=b 10<=20 1
> greater than a>b 10>20 0
>= greater than (or) equal to a>=b 10>=20 0
== equal to a==b 10==20 0
!= not equal to a!=b 10!=20 1
Example for Relational Operators
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
3. LOGICAL OPERATORS
• Logical operators are used to combine 2 (or) more expressions logically.
• These are like special tools that help in making decisions in our programs based on true or false answers.
• The logical operator && and || are used to test more than one condition and makes decisions
• There are three types of logical operators. they are as follows:
• Logical AND (&&)
• Logical OR ( || )
• Logical NOT (!)
Syntax:
Exp 1 Logical operator 1 or 2 or 3 Exp 2
• When combine two or more relational expressions is termed as a logical expression or a compound relational
expressions.
• if either or both value become false , then the expression is also false.
Example: Operator Description Example a=20,b=10 Output
&& logical AND (a>b)&&(a<c) (10>20)&&(10<30) 0
|| logical OR (a>b)||(a<=c) (10>20)||(10<30) 1
! logical NOT !(a>b) !(10>20) 1
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
4. ASSIGNMENT OPEARTOR
• Assignment operators are symbols that help us give values to variables.
• They are used when we want to store a value in a variable.
The types of assignment operators are −
• Simple assignment.
• Compound assignment.
Simple Assignment
• The simple assignment operator (=) is used to give a value to a variable.
• It takes the value on the right side and puts it in the variable on the left side.
• It’s like putting a number or word inside a particular box.
Compound Assignment
• The compound assignment operators do two things at once.
• Firstly, they do a math operation like adding, subtracting, multiplying, or dividing, and then they store the
result back in the very same variable.
EXAMPLE:
Operator Description Example
=
simple
assignment
a=10
+=,-=,*=,/=,%=
compound
assignment
a+=10"a=a+10
a=10"a=a-10
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
5. INCREMENT AND DECREMENT OPERATOR
1. Increment operator (++)
• This operator increments the value of a variable by 1
The two types include
• pre increment
• post increment
Pre- increment
• If we place the increment operator before the operand, then it is pre-increment.
• The value is first incremented, and the next operation is performed on it.
For example,
z = ++a; // a= a+1
z=a
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Post - Increment
• If we place the increment operator after the operand, then it is post-increment,
• The value is incremented after the operation is performed.
For example,
z = a++; // z=a
a= a+1
2. Decrement operator − (- -)
• It is used to decrement the values of a variable by 1.
The two types are −
• pre decrement
• post decrement
• If the decrement operator is placed before the operand, then it is called pre-decrement.
• Here, the value is first decremented and then, operation is performed on it.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
For example,
z = - - a; // a= a-1
z=a
•If the decrement operator is placed after the operand, then it is called post-decrement.
•Here, the value is decremented after the operation is performed.
For example,
z = a--; // z=a
a= a-1
6. CONDITIONAL OPERATOR(? :)
• The conditional operator, also known the ternary operator,
• It is a simple and easy way to make decisions in programming.
• It allows us to choose one value from two options based on a particular condition.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Syntax:
exp1? exp2: exp3
Where exp1, exp2, exp3 are expressions.
The operator ?: works as follows:
1. exp1 is evaluated first .
2. If it is non- zero(true) then the exp 2 is evaluated and become the value of expression .
3. if exp 1 is false , exp3 is evaluated and it becomes the value of the expression.
4. note: Only one of the expression (either exp2 or exp3 ) is evaluated.
Example:
a=10;
b=15;
x=(a>b)? a: b;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
7. BITWISE OPERATOR
• Bitwise operators work directly with the binary (bit-level) form of numbers.
• In computers, numbers are stored as a series of 0s and 1s, called bits.
• Bitwise operators help us manipulate these bits directly, which can be very useful for certain types of
programming tasks.
Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Left Shift
>> Right shift
~ One's Complement
1. Bitwise AND (&)- operator compares two numbers bit by bit from the right side. If both bits are 1 result
will be 1, If any of both bits is 0 result will be 0.
Example : 5 & 3;
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
2. Bitwise OR( | )- This operator compares number bit by bit. if any of bits is 1 result will be 1. If both bit are
0 result will be 0.
Example : 5 | 3;
3. Bitwise XOR(^)- This operator compares two numbers bit by bit. If both bits are 1 or both are 0, the result
will be 0; if they are different, the result is 1.
Example : 5 ^ 3;
4. Left Shift(<<)
• If the value is left shifted one time, then its value gets doubled. it's like we are multiplying the number by 2
each time we do left shift. Example, a = 10, then a<<1 = 20
5. Right shift(>>)
• If the value of a variable is right-shifted one time, then its value becomes half the original value. it's
opposite to left shift here it's just like we are dividing a number by 2 each time we do the right shift.
Example, a = 10, then a>>1 = 5
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
8. SPECIAL OPERATORS
Some of the special operations are comma, ampersand (&), size of operators, pointer operator(*) and member selection
operator (-->).
• Comma ( , ) −
- this can be used to link the related expressions together .
-It is used as separator for variables.
For example : 1 a=10, b=20;
example 2: value =(x=10,y=5,x+y);
• Address (&) − It get the address of a variables.
• Size of ( ) −
- the size of( ) is a compile time operator and it is used with operand , it returns the number of bytes the operand
occupies.
-It is used to get the size of a data type of a variable in bytes.
Example:
m=sizeof(sum);
n=sizeof(long int);
k= sizeof(235L)
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
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.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
Types of Expressions
Constant expressions: Constant Expressions consists of
only constant values. A constant value is one that doesn’t
change.
Example:
5, 10 + 5 / 6.0, ‘x’
2. Integral expressions: Integral Expressions are those
which produce integer results after implementing all the
automatic and explicit type conversions.
Example
x, x * y, x + int( 5.0)
where x and y are integer variables.
3. 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.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
4. 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
5. Logical expressions:
- Logical Expressions combine two or more relational expressions and produces bool type
results.
Examples:
x > y && x == 10, x == 10 || y == 5
6. Pointer expressions: Pointer Expressions produce address values.
Examples:
&x, ptr, ptr++
where x is a variable and ptr is a pointer
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
7. 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.
Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore

More Related Content

Similar to Computer Programming In C - Variables, Constants & Data Types (20)

C programming
C programmingC programming
C programming
KarthicaMarasamy
 
C programming language:- Introduction to C Programming - Overview and Importa...
C programming language:- Introduction to C Programming - Overview and Importa...C programming language:- Introduction to C Programming - Overview and Importa...
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
chapter 1.pptx
chapter 1.pptxchapter 1.pptx
chapter 1.pptx
SeethaDinesh
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
C programming
C programming C programming
C programming
Rohan Gajre
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
Suraj Das
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
Jesmin Akhter
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
saivasu4
 
C language
C languageC language
C language
marar hina
 
EC2311-Data Structures and C Programming
EC2311-Data Structures and C ProgrammingEC2311-Data Structures and C Programming
EC2311-Data Structures and C Programming
Padma Priya
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
The New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of theThe New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
computer networksssssssssssssssssssssssssssss.pptx
computer networksssssssssssssssssssssssssssss.pptxcomputer networksssssssssssssssssssssssssssss.pptx
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
Unit ii
Unit   iiUnit   ii
Unit ii
sathisaran
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 
C programming language:- Introduction to C Programming - Overview and Importa...
C programming language:- Introduction to C Programming - Overview and Importa...C programming language:- Introduction to C Programming - Overview and Importa...
C programming language:- Introduction to C Programming - Overview and Importa...
SebastianFrancis13
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
Basic Information About C language PDF
Basic Information About C language PDFBasic Information About C language PDF
Basic Information About C language PDF
Suraj Das
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
saivasu4
 
EC2311-Data Structures and C Programming
EC2311-Data Structures and C ProgrammingEC2311-Data Structures and C Programming
EC2311-Data Structures and C Programming
Padma Priya
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
Shankar Gangaju
 
The New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of theThe New Yorker cartoon premium membership of the
The New Yorker cartoon premium membership of the
shubhamgupta7133
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Rohit Singh
 
computer networksssssssssssssssssssssssssssss.pptx
computer networksssssssssssssssssssssssssssss.pptxcomputer networksssssssssssssssssssssssssssss.pptx
computer networksssssssssssssssssssssssssssss.pptx
bmit1
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
Ajeet Kumar
 

Recently uploaded (20)

Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Cisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdfCisco ISE Performance, Scalability and Best Practices.pdf
Cisco ISE Performance, Scalability and Best Practices.pdf
superdpz
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Ad

Computer Programming In C - Variables, Constants & Data Types

  • 1. UNIT- 1 OVERVIEW OF C 1. History of C Language ⮚ The root of all modern language is ALGOL, introduced in the early 1960 ⮚ ALGOL was developed by Corrado Bohm, it was the 1st computer language ⮚ In 1967, Martin Richard developed a language called BCPL( Basic Combined Programming Language) ⮚ In 1970, Ken Thompson, developed B language – it is an early version of UNIX operating system ⮚ In 1972, Dennis Ritchie was evolved a C language at Bell Laboratories ⮚ C is a programming language ⮚ It is a structured, high-level, machine independent language ⮚ It allows software developers to develop programs ⮚ C is running under a variety of operating system and hardware platforms Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 2. Features of C Language C is the widely used language. It provides many features that are given below. • Simple • Machine Independent or Portable • Mid-level programming language • Structured programming language • Rich Library • Memory Management • Fast Speed • Pointers • Recursion • Extensible Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 3. 2. IMPORTANCE OF C- PROGRAMMING • C is called as a robust language, which has so many built-in functions and operations, which can be used to write any complex program. • C as a middle level language. • The ‘C’ compiler combines the capabilities of an assembly language with the features of a high-level language. • It is the best for writing both system software and business packages. • ‘C’ Programs are efficient and fast. • C is highly portable • Because ‘C’ programs written on one computer can be run on another with little (or) no modification. • ‘C’ language is best for structured programming, where the user can think of a problem in terms of function modules (or) blocks. • It has the ability to extend itself. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 4. 3. Structure of C- Programming Language ❖Preprocessor Directives: Used to include libraries or header files. ❖Global Declarations: Optional variables or function prototypes that are available to all functions. ❖main() Function: The entry point for program execution. ❖Local Variables: Declared inside functions to hold temporary data. ❖ Statements and Expressions: Code that performs operations or computations. ❖ Return Statement: Indicates program termination and success. ❖Functions: Additional code modules that perform specific tasks, improving readability and reusability. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 5. Basic Structure of a C Program #include <stdio.h> // Preprocessor Directive // Global Variable Declarations (if any) // Function Prototypes (if any) // Main Function int main() { // Local Variable Declarations // Code Statements return 0; // Return statement } // Additional Functions (if any) Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 6. EXECUTING C- PROGRAM Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 7. 1. Preprocessor Directives (#include and others) ∙ These are lines starting with # ∙ Processed before the compilation of the actual code. ∙ They allow for the inclusion of libraries or files that provide additional functionality. Example: ✔#include <stdio.h> - #include <stdio.h>: This includes the Standard Input Output (stdio) library that provides functions for I/O operations like printf(), scanf(), etc. ✔#include <stdlib.h> - #include <stdlib.h>: Includes the Standard Library for memory allocation, random number generation, and other utility functions. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 8. 2. Global Declarations (Optional) ∙ Global variables or function prototypes can be declared outside any function ∙ Usually before the main() function. ∙ Global variables can be accessed by any function in the program. Example: ✔ int globalVariable = 10; // A global variable 3. The main() Function ∙ The main() function is the starting point of a C program. ∙ Every C program must have a main() function. ∙ It’s where the program execution begins. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 9. Syntax: int main( ) { // Statements to be executed return 0; // Indicates successful execution } ❖Return Type: The main() function typically returns an integer (int), with 0 generally indicating successful execution ❖Statements inside main(): This includes variable declarations, input/output operations, function calls, and other logic. Example : int main( ) { printf(“ HELLO”); return 0; } Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 10. 4. Local Variable Declarations ✔Inside the main() function (or other functions), local variables are declared. ✔Local variables are used for storing data during the program’s execution and are only accessible within the function they are declared in. Example: int x = 5; // Local variable declaration char letter = 'A'; // Another local variable 5. Statements and Expressions ✔The statements inside the main() function define the program’s behavior. ✔This includes assignments, input/output, conditional statements, loops, etc. Examples: printf("Hello, World!n"); // Output statement int y = x + 10; // Arithmetic expression Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 11. 6. Return Statement ✔ return 0; is used to indicate the program has completed successfully. ✔ In the main() function, this is important because it signals the operating system that the program ended without errors. ✔ Other functions might return values that are used by the program. 7. Functions (Optional) ∙ C programs can have additional functions that are defined outside the main() function. ∙ These can be called from main() or other functions to break the code into smaller, manageable pieces. Syntax of a function: int add(int a, int b) { return a + b; } Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 12. 4. PROGRAMMING STYLE CONSTANTS, VARIABLES AND DATA TYPES Programming Style: ∙ Consistent indentation, meaningful variable names, and proper commenting improve code readability Constants: ∙ #define is used for simple constants, while const allows type safety and better debugging Variables: ∙ Declare variables with appropriate data types and initialize them properly Data Types: ∙ Use the appropriate data type (int, float, double, char, etc.) based on the kind of data the variable will hold ∙ C provides both primitive (e.g., int, char) and derived data types (e.g., arrays, structures) Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 13. 1. Programming Style in C ✔Programming style refers to the conventions and practices you follow while writing your code. ✔It ensures that the code is readable, maintainable, and understandable for both yourself and others. ✔Consistent style improves collaboration and debugging. Key elements of programming style include: 1. Indentation and Formatting: o Use consistent indentation to make the code easy to follow (e.g., 4 spaces or 1 tab per indentation level). o Code blocks (e.g., loops, functions) should be properly indented. o Use blank lines to separate logical blocks of code. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 14. Example: 1 if (x > 10) { printf("x is greater than 10n"); } 2. Meaningful Variable Names: o Choose descriptive names for variables, functions, and constants. o Use meaningful names that indicate the purpose of the variable (e.g., count, totalAmount, temperature). Example:2 int number Of Students; // Descriptive variable name o Add comments to explain what your code is doing, especially for complex logic. o Use comments to clarify non-obvious sections of code. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 15. CONSTANTS, VARIBLES AND DATA TYPES CHARACTER SET • The character set in C is a collection of characters that the C language recognizes and uses to form words, expressions, and numbers: • Alphabets: The 26 uppercase and 26 lowercase letters of the English alphabet • Digits: The numerals 0–9 • Special characters: Symbols such as +, -, *, /, =, <, >, & , |, !, ^, ~, %, #, , ;, :, ', " • Whitespace characters: Spaces, tabs, newlines, and form feeds • Escape sequences: Characters with special meanings that are prefixed with a backslash, such as n (newline), t (tab), (backslash character), ' (single quote), and " (double quote) TRIGRAPH CHARACTERS - A trigraph is a sequence of three characters that is used to represent punctuation characters. - Trigraphs are used when a character set doesn't have convenient graphic representations for some punctuation characters. Examples of trigraph are Trigraph Character ??/ — ??< { ??- ~ Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 16. C TOKENS • A token in C can be defined as the smallest individual element of the C programming language that is meaningful to the compiler. • It is the basic component of a C program. • The tokens of C language can be classified into six types based on the functions they are used to perform. 1. Keywords: • The keywords are pre-defined or reserved words in a programming language. • Each keyword is meant to perform a specific function in a program. • keywords are referred names for a compiler, they can’t be used as variable names You cannot redefine keywords. • C language supports 32 keywords which are given below: auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 17. 2. Identifiers: • Identifiers are used for naming of variables, functions, and arrays. • Once declared, you can use the identifier in later program statements to refer to the associated value. • A special identifier called a statement label can be used in goto statements. Rules for Naming Identifiers • Certain rules should be followed while naming c identifiers which are as follows: • They must begin with a letter or underscore(_). • They must consist of only letters, digits, or underscore. No other special character is allowed. • It should not be a keyword. • It must not contain white space. • It should be up to 31 characters long as only the first 31 characters are significant. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 18. CONSTANTS Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 19. Integer Constants • Integer constants are sequences of integers with a fixed value. • They must not contain any decimal points or fractional numbers. • Integer constants can either be positive or negative numbers. • They include decimal system integers, octal system integers, hexadecimal system integers. 1.Decimal integers – Set of digits ranging from 0 to 9. For Example – const int y = 123; 2.Octal integers – Set of digits ranging from 0 to 7 which start with the number ‘0’ in the beginning/at the prefix. For example – const int x = 032; 3.Hexadecimal integers – Set of digits ranging from 0 to 9 and alphabets from A to F where A indicates number 10 and F indicates number 15. 0x is used at the prefix of the value. For example – const int z = 0x14; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 20. Real Constants or Floating-point Constants • They contain fractional numbers that can be written in 2 forms, Fractional form, and Exponential form. • Eg. 140.9, 4578.218, 4.1 e 45 (i.e. 4.1 * 10^45), 5.0 e -2 (i.e. 5.0 * 10^-2) Character Constants • Any single character from the defined character set is called a character constant. • They include a single alphabet, single-digit, single symbol enclosed within single inverted commas. • Eg. ‘A’, ‘p’, ‘4’, ‘$’, ‘=’ String Constants • It contains a set/collection of characters that should be enclosed within double inverted commas. • Eg. “Hello”, “Length”, “ND123” Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 21. Backslash character constant • A backslash ( ) that allows a visual representation of some nongraphic characters introduces an escape. • One of the common escape constants is the newline character( ). Examples: haracter Meaning ‘a’ alert ‘b’ backspace ‘f’ form feed ’n’ newline ‘t’ horizontal tab ‘r’ carriage return ‘v’ vertical tab ‘’ backslash ‘’ ’ single quote ‘" ’ double quote ‘?’ Question mark Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 22. VARIABLES • Variables are key building elements of the C programming language • It is used to store and modify data in computer programs. • A variable is a designated memory region that stores a specified data type value. • Each variable has a unique identifier, its name, and a data type describing the type of data it may hold. Syntax: The syntax for defining a variable in C is as follows: data_type variable _name ; Rules: • variable_name: It is the identifier for the variable, i.e., the name you give to the variable to access its value later in the program. • The variable name must follow specific rules, like starting with a letter or underscore and consisting of letters, digits, and underscores. • An example of declaring the variable is given below: int a; float b; char c; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 23. DATA TYPES • C language is rich in data types. • 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. • Each data type requires different amounts of memory and has some specific operations which can be performed over it. There are 3 types of data types: 1. Primary or fundamental data types- Primitive data types are the most basic data types that are used for representing simple values such as integers, float, characters, etc. Example: int, char, float, double, void 2. Derived data types- The data types that are derived from the primitive or built-in datatypes are referred to as Derived Data Types. Example: array, pointers, function 3. User-defined datatypes - The user-defined data types are defined by the user himself. Example : structure, union, enum Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 24. 1. Integer Types: The integer datatype in C is used to store the integer numbers (any number including positive, negative and zero without decimal part). Octal values, hexadecimal values, and decimal values can be stored in int data type in C. • Range: -2,147,483,648 to 2,147,483,647 • Size: 4 bytes • Format Specifier: %d Syntax of Integer: int var_name; Example: int a; // Declaration int a=10; // initialization Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 25. • The integer data type can also be used as 1.unsigned int: Unsigned int data type in C is used to store the data values from zero to positive numbers but it can’t store negative values like signed int. 2.short int: It is lesser in size than the int by 2 bytes so can only store values from -32,768 to 32,767. 3.long int: Larger version of the int datatype so can store values greater than int. 4.unsigned short int: Similar in relationship with short int as unsigned int with int. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 26. 2. Floating Point Types: • In C programming float data type is used to store floating-point values. • Float in C is used to store decimal and exponential values. • It is used to store decimal numbers (numbers with floating point values) with single precision. • Range: 1.2E-38 to 3.4E+38 • Size: 4 bytes • Format Specifier: %f Syntax of float : float var_name; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 27. Example: float a = 9.0f; 3. Void Data Type: • The void data type in C is used to specify that no value is present. • It does not provide a result value to its caller. • It has no values and no operations. • It is used to represent nothing. • Void is used in multiple ways as function return type, function arguments as void, and pointers and void. 4. Character Type: • Character data type allows its variable to store only a single character. • The size of the character is 1 byte. It is the most basic data type in C. • It stores a single character and requires a single byte of memory in almost all compilers. • Range: (-128 to 127) or (0 to 255) • Size: 1 byte .Format Specifier: %c Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 28. Syntax of char •The char keyword is used to declare the variable of character type: char var_name; Example: char a = 'a'; char c; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 29. Declaration Of Variables • The declaration of the variable must be done before they are used in the program. • Declaration of variables does two things: 1. It tells the compiler what the variable name is 2. It specifies what type of data the variable will hold. Two types of Declaration: 3. Primary type declaration 4. User- Defined type declaration. 1. Primary Type Declaration: A variable can be used to store a value of any data type. Syntax: data-type v1,v2,…., vn; • V1, v2, v3,…,vn are the names of the variables. • Variables are separated by commas. • A declaration statement must end with a semicolon. • Example: int count; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 30. 2. User defined Type Declaration: The data types defined by the user themself are referred to as user-defined data types. These data types are derived from the existing datatypes. Need of User-Defined Datatypes • It enables customization in the code. • Users can write more efficient and flexible code. • Provides abstraction. Types of User-Defined Data Types 1. Enumeration (enums) • Enum is short for "Enumeration". • It allows the user to create custom data types with a set of named integer constants. • The "enum" keyword is used to declare an enumeration. Enum simplifies and makes the program more readable. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 31. Syntax: enum enum_name {const1, const2, ..., const N}; •Here, the const1 will be assigned 0, const2 = 1, and so on in the sequence. •We can also assign a custom integer value such as: Example: 1 enum enum_name { const1 = 8; const2 = 4; } Example 2: enum day { Monday , Tuesday,…, Sunday}; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 32. 2. typedef • typedef is used to redefine the existing data type names. • It is used to provide new names to the existing data types. • The "typedef" keyword is used for this purpose; Syntax typedef type identifier; Example: typedef int units; typedef float marks; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 33. OPERATORS AND EXPRESSIONS • Operators are special symbols in C that performs an operation on values and variables. • These special symbols allow us to manipulate data and variables in different ways. Those Operators are classified into the following • Arithmetic operators. • Relational operators. • Logical operators. • Assignment operators. • Increment and decrement operators. • Bitwise operators. • Conditional operators. • Special operators. 1. ARITHMETIC OPERATORS • Arithmetic operators are used for numerical calculations (or) to perform arithmetic operations like addition, subtraction etc. • There are 3 types of arithmetic operators 1. Integer arithmetic 2. Real arithmetic 3. Mixed mode arithmetic Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 34. Operator Description Example a=20,b=10 Output + Addition a+b 20+10 30 - subtraction a-b 20-10 10 * multiplication a*b 20*10 200 / Division a/b 20/10 2(quotient) % Modular Division a%b 20%10 0 (remainder) Examples of Arithmetic operations Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 35. Example code: #include<stdio.h> void main () { int a= 20, b = 10; printf (" %d", a+b); printf (" %d", a-b); printf (" %d", a*b); printf (" %d", a/b); printf (" %d", a%b); } Output •30 10 200 20 Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 36. 1. Integer Arithmetic: • when both the operands in a single arithmetic expressions such as a+b are integers, these expression are called as integer expressions • These operations are called integer arithmetic • Integer arithmetic always yields an integer value • The largest integer values depends on machine • During Division, if both the operands are of same sign the result is truncated towards zero • if one of them is negative , the direction of truncation is implementation dependent Example: 6/7=0 and -6/-7=0 but -6/7 may be zero or -1(machine dependent) • During Modulo division , the sign of the result is always the sign of the first operand Example : -14 % 3= -2 or -14 % -3 = -2 or 14 % -3= 2 2. Real Arithmetic: • An arithmetic operation involving only real operands is called real arithmetic • A real operand may assume values either in decimal or exponential notation • Since floating point values are rounded to the number of significant digits permissible • The final value is an approximation of the correct result. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 37. Example: If x ,y , z are floats then we will have x= 6.0/7.0=0.857143 Y= 1.0/3.0 =0.333333 Z= -2.0/3.0= -0.66667 3.Mixed mode Arithmetic: When one or more operands is real and the other is integer , the expression is called a mixed mode arithmetic expressions. If either operand is of real type, then only the real operation is performed, and the result is always a real number. Example : 15/10.0= 1.5 Whereas 15/10=1 2. RELATIONAL OPERATORS • Relational operators are used for comparing two expressions such as greater, lesser, equal, not equal. • The operators used are < , <=, >, >= , = =, != . • The output of a relational expression is either true (1) (or) false (0). Syntax: Expression 1 relational operator expression 2 Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 38. Operator Description Example a=20,b=10 Output < less than a<b 10<20 1 <= less than (or) equal to a<=b 10<=20 1 > greater than a>b 10>20 0 >= greater than (or) equal to a>=b 10>=20 0 == equal to a==b 10==20 0 != not equal to a!=b 10!=20 1 Example for Relational Operators Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 39. 3. LOGICAL OPERATORS • Logical operators are used to combine 2 (or) more expressions logically. • These are like special tools that help in making decisions in our programs based on true or false answers. • The logical operator && and || are used to test more than one condition and makes decisions • There are three types of logical operators. they are as follows: • Logical AND (&&) • Logical OR ( || ) • Logical NOT (!) Syntax: Exp 1 Logical operator 1 or 2 or 3 Exp 2 • When combine two or more relational expressions is termed as a logical expression or a compound relational expressions. • if either or both value become false , then the expression is also false. Example: Operator Description Example a=20,b=10 Output && logical AND (a>b)&&(a<c) (10>20)&&(10<30) 0 || logical OR (a>b)||(a<=c) (10>20)||(10<30) 1 ! logical NOT !(a>b) !(10>20) 1 Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 40. 4. ASSIGNMENT OPEARTOR • Assignment operators are symbols that help us give values to variables. • They are used when we want to store a value in a variable. The types of assignment operators are − • Simple assignment. • Compound assignment. Simple Assignment • The simple assignment operator (=) is used to give a value to a variable. • It takes the value on the right side and puts it in the variable on the left side. • It’s like putting a number or word inside a particular box. Compound Assignment • The compound assignment operators do two things at once. • Firstly, they do a math operation like adding, subtracting, multiplying, or dividing, and then they store the result back in the very same variable. EXAMPLE: Operator Description Example = simple assignment a=10 +=,-=,*=,/=,%= compound assignment a+=10"a=a+10 a=10"a=a-10 Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 41. 5. INCREMENT AND DECREMENT OPERATOR 1. Increment operator (++) • This operator increments the value of a variable by 1 The two types include • pre increment • post increment Pre- increment • If we place the increment operator before the operand, then it is pre-increment. • The value is first incremented, and the next operation is performed on it. For example, z = ++a; // a= a+1 z=a Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 42. Post - Increment • If we place the increment operator after the operand, then it is post-increment, • The value is incremented after the operation is performed. For example, z = a++; // z=a a= a+1 2. Decrement operator − (- -) • It is used to decrement the values of a variable by 1. The two types are − • pre decrement • post decrement • If the decrement operator is placed before the operand, then it is called pre-decrement. • Here, the value is first decremented and then, operation is performed on it. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 43. For example, z = - - a; // a= a-1 z=a •If the decrement operator is placed after the operand, then it is called post-decrement. •Here, the value is decremented after the operation is performed. For example, z = a--; // z=a a= a-1 6. CONDITIONAL OPERATOR(? :) • The conditional operator, also known the ternary operator, • It is a simple and easy way to make decisions in programming. • It allows us to choose one value from two options based on a particular condition. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 44. Syntax: exp1? exp2: exp3 Where exp1, exp2, exp3 are expressions. The operator ?: works as follows: 1. exp1 is evaluated first . 2. If it is non- zero(true) then the exp 2 is evaluated and become the value of expression . 3. if exp 1 is false , exp3 is evaluated and it becomes the value of the expression. 4. note: Only one of the expression (either exp2 or exp3 ) is evaluated. Example: a=10; b=15; x=(a>b)? a: b; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 45. 7. BITWISE OPERATOR • Bitwise operators work directly with the binary (bit-level) form of numbers. • In computers, numbers are stored as a series of 0s and 1s, called bits. • Bitwise operators help us manipulate these bits directly, which can be very useful for certain types of programming tasks. Operator Description & Bitwise AND | Bitwise OR ^ Bitwise XOR << Left Shift >> Right shift ~ One's Complement 1. Bitwise AND (&)- operator compares two numbers bit by bit from the right side. If both bits are 1 result will be 1, If any of both bits is 0 result will be 0. Example : 5 & 3; Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 46. 2. Bitwise OR( | )- This operator compares number bit by bit. if any of bits is 1 result will be 1. If both bit are 0 result will be 0. Example : 5 | 3; 3. Bitwise XOR(^)- This operator compares two numbers bit by bit. If both bits are 1 or both are 0, the result will be 0; if they are different, the result is 1. Example : 5 ^ 3; 4. Left Shift(<<) • If the value is left shifted one time, then its value gets doubled. it's like we are multiplying the number by 2 each time we do left shift. Example, a = 10, then a<<1 = 20 5. Right shift(>>) • If the value of a variable is right-shifted one time, then its value becomes half the original value. it's opposite to left shift here it's just like we are dividing a number by 2 each time we do the right shift. Example, a = 10, then a>>1 = 5 Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 47. 8. SPECIAL OPERATORS Some of the special operations are comma, ampersand (&), size of operators, pointer operator(*) and member selection operator (-->). • Comma ( , ) − - this can be used to link the related expressions together . -It is used as separator for variables. For example : 1 a=10, b=20; example 2: value =(x=10,y=5,x+y); • Address (&) − It get the address of a variables. • Size of ( ) − - the size of( ) is a compile time operator and it is used with operand , it returns the number of bytes the operand occupies. -It is used to get the size of a data type of a variable in bytes. Example: m=sizeof(sum); n=sizeof(long int); k= sizeof(235L) Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 48. 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. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 49. Types of Expressions Constant expressions: Constant Expressions consists of only constant values. A constant value is one that doesn’t change. Example: 5, 10 + 5 / 6.0, ‘x’ 2. Integral expressions: Integral Expressions are those which produce integer results after implementing all the automatic and explicit type conversions. Example x, x * y, x + int( 5.0) where x and y are integer variables. 3. 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. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 50. 4. 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 5. Logical expressions: - Logical Expressions combine two or more relational expressions and produces bool type results. Examples: x > y && x == 10, x == 10 || y == 5 6. Pointer expressions: Pointer Expressions produce address values. Examples: &x, ptr, ptr++ where x is a variable and ptr is a pointer Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore
  • 51. 7. 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. Dr.V.Deepa, Assistant Professor, Department of Information Technology, Sri Ramakrishna College of Arts & Science, Coimbatore