SlideShare a Scribd company logo
1 of 63
C PROGRAMMING
LANGUAGE
AGENDA
• What is c language?
• History of c language.
• Features of c language.
• Applications of c language.
• Compilation process in c.
• Editors.
• Gcc complier.
• Basic structure of c program.
WHAT IS C LANGUAGE?
• C programming is considered as the base for other programming languages, that is why it is
known as mother language.
• C programming is considered as general purpose programming .
• It can be defined by the following ways:
1. Mother language.
2. System programming language.
3. Procedural oriented programming language.
4. Structured programming language.
5. Mid level programming language.
HISTORY OF C LANGUAGE
• C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of
at&t(American telephone & telegraph), located in U.S.A.
• Dennis Ritchie is known as founder of c language.
• It was developed to be used in UNIX operating system.
FEATURES OF C LANGUAGE
C is the widely used language. It provides
many features that are given below.
1.Simple
2.Machine independent or portable
3.Mid-level programming language
4.Structured programming language
5.Rich library
6.Memory management
7.Speed
8.Pointers
9.Recursion
10.Extensible
FEATURES OF C LANGUAGE
• SIMPLE :- C IS A SIMPLE LANGUAGE IN THE SENSE IT PROVIDES THE RICH SET OF LIBRARY
FUNCTIONS, DATA TYPES, ETC.
• MACHINE INDEPENDENT OR PORTABLE :- C IS A MACHINE INDEPENDENT LANGUAGE.
• MID – LEVEL PROGRAMMING LANGUAGE :- IT SUPPORTS THE FEATURES OF LOW LEVEL AND
HIGH LEVEL LANGUAGES.
• STRUCTURED PROGRAMMING LANGUAGE :- IT CAN BREAK THE PROGRAM INTO PARTS USING
FUNCTIONS.
• RICH LIBRARY :- IT PROVIDES THE LOT OF INBUILT FUNCTION THAT MAKE THE DEVELOPMENT
FAST.
• MEMORY MANAGEMENT :- IT SUPPORTS THE FEATURE OF DYNAMIC MEMORY ALLOCATION.
• SPEED :- THE COMPILATION AND EXECUTION TIME OF C LANGUAGE IS FAST.
• POINTER :- WE CAN DIRECTLY INTERACT WITH THE MEMORY BY USING THE POINTERS.
• RECURSION :- WE CAN CALL THE FUNCTION WITHIN THE FUNCTION. IT PROVIDES CODE
REUSABILITY OF EVERY FUNCTION.
• EXTENSIBLE :- IT CAN EASILY ADOPT NEW FEATURES.
APPLICATIONS OF C LANGUAGE
• Embedded systems.
• System applications.
• Desktop applications.
• Developing browsers.
• Databases.
• Operating systems.
• Compliers.
COMPILATION PROCESS OF C
• What is compilation?
- The compilation is a process of converting the source code into object code. it is done with the help
of the compiler.
- The c compilation process converts the source code taken as input into the object code or machine
code.
- The compilation process can be divided into four steps, i.e., pre-processing, compiling, assembling,
and linking.
Preprocessor
- The source code is first passed to the preprocessor, and
then the preprocessor expands this code. after expanding the
code, the expanded code is passed to the compiler.
Complier
- The compiler converts this code into assembly code.
Assembler
- The assembly code is converted into object code by
using an assembler.
Linker
- The linker is to link the object code of our program
with the object code of the library files and other files. the output
of the linker is the executable file.
HOW TO INSTALL C
Code Editors :- There are many compilers available for c.
• Code blocks
• Turbo c++
• Eclipse
• Notepad++
• VS code
You need to download any one. here, we are going to use vs code.
• Install the extension c in vs code.
GNU complier collection:- Mingw-w64 - for 32 and 64 bit windows
- The mingw-w64 project is a complete runtime
Environment for gcc to support binaries native to
Windows 64-bit and 32-bit operating systems.
BASIC STRUCTURE OF C PROGRAM
Header Files
----------
----------
----------
Main(){
-----------
-----------
User Defined Functions
-----------
-----------
}
#include<stdio.h>
int main()
{
Printf(“Hello World”);
Printf(“Welcome to C program”);
Printf(“Welcome to acube”);
}
PRINTF() AND SCANF() IN C
• The printf() and scanf() functions are used for input and output in c language.
• Both functions are inbuilt library functions, defined in stdio.h (header file).
printf() function
• The printf() function is used for output. it prints the given statement to the console.
printf ("format string", argument_list);
• The format string can be %d (integer), %c (character), %s (string), %f (float) etc.
scanf() function
• The scanf() function is used for input. it reads the input data from the console.
scanf("format string", argument_list);
VARIABLES IN C
• A variable is a name of the memory location.
• It is used to store data.
• Its value can be changed, and it can be reused many times.
Syntax to declare a variable:
- Syntax
- datatype variable name=datatype value;
- Examples defining a variable
- int f; - int f = 10;
BASIC OR PRIMARY DATA TYPES
In c, there are four basic data types
• int
• char
• float
• double
Basic or Primary
Data types
Floating Point
(Float)
Character
(char)
Integer
(int)
Double
(double)
Basic Data Types Short Form Description Example
Integer int Whole Numbers int age=20;
Floating Point float Fractional or
Decimal Values
float price=10.50;
Double double Fractional or
Decimal Values
double
price=10.50230;
Character char Character Values char symbol=‘A’;
RULES FOR USING VARIABLES IN C
• The variable name can contain letters, digits and the underscore( _ ) .
Example:- age_20.
• The first character of the variable name must be a letter or underscore( _ ).
Example:- _abc123, abc_123
• Variable name must not be same as c reserved words or keywords.
Example:- int, float, char
• No other special symbols or characters (#, &, $, !,@,%) other than underscore(_).
Example:- abc@123.
• Variables names are the case sensitive. Example:- name and NAME are the two different variables.
• It should not contain white spaces. Example:- User name.
• The length of the variable name should not be more than 31 characters.
- VALID VARIABLE NAMES - INVALID VARIABLE NAMES
- int a; - int 2;
- int _ab; - int a b;
- int a30; - int long;
TYPES OF VARIABLES IN C
1. Local Variables: A variable that is declared inside the function
or block is called a local variable.
Example:- int main()
{
int a=10; //local variable
printf(“the value of a is %d”, a);
}
2. Global Variables: A variable that is declared outside the
function or block is called a global variable.
Example:- int value=20;//global variable
void function1() {
printf(“%dn”, x);
}
void function2() {
printf(“%dn”, x);
}
int main(){
function1();
function2();
}
• Static Variables: A variable that retains its value between multiple function calls is known as a static variable. It is
declared with the static keyword.
Example:- #include <stdio.h>
void function(){
int x = 20;//local variable
static int y = 30;//static variable
x = x + 10;
y = y + 10;
printf("n%d,%d", x, y);
}
int main() {
function();
function();
function();
}
• Automatic Variable: All variables in C that are declared inside the block, are automatic variables by default. We can
explicitly declare an automatic variable using the auto keyword. Automatic variables are similar to local variables.
Example:- #include <stdio.h>
void function()
{
int x=10;//local variable (also automatic)
auto int y=20;//automatic variable
}
int main() {
function();
}
• External variables :-
- extern is short name for external.
- Used when a particular file needs to access a variable from another file.
- Declaration and Definition Declaration
- int var ; - extern int var;
DATATYPES IN C
A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
There are the following data types in C language.
• Primary data types
The primary data types in the c programming language are the basic data types. all the primary data
types are already defined in the system. Primary data types are also called as built-in data types. The
following are the primary data types in c programming language.
• Integer data type
• Floating Point data type
• Double data type
• Character data type
INTEGER DATATYPE
• The integer data type is a set of
whole numbers.
• Every integer value does not have
the decimal value.
• we use the keyword "int" to
represent integer data type in c.
• The integer data type is used with
different type modifiers like short,
long, signed and unsigned.
• The following table provides
complete details about the integer
data type.
FLOATING POINT DATATYPES
• Floating-point data types are a set of numbers with the decimal
value.
• Every floating-point value must contain the decimal value.
• The floating-point data type has two variants...
• float
• double
• we use the keyword "float" to represent floating-point data
type and "double" to represent double data type in c.
• Both float and double are similar but they differ in the number
of decimal places.
• The float value contains 6 decimal places whereas double
value contains 15 or 19 decimal places.
• The following table provides complete details about floating-
point data types.
CHARACTER DATA TYPE
• The character data type is a set of characters enclosed in single quotations.
• The following table provides complete details about the character data type.
The following table provides complete information about all the data types in c programming language.
TO CALCULATE THE SIZE OF ALL DATATYPES USING THE
'SIZEOF' OPERATOR
sizeof(datatype) operator
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.
TOKENS IN C PROGRAM
• Tokens in c is the most important element to be used in creating a program in c.
• We can define the token as the smallest individual element in C.
• For example, we cannot create a sentence without using words; similarly, we cannot create a program
in C without using tokens in C.
• Tokens in C is the building block or the basic component for creating a program in c language.
• Tokens in C language can be divided into the following categories:
KEYWORDS IN C
Keywords in C can be defined as the pre-defined or the reserved words having its own importance, and each
keyword has its own functionality.
A keyword is a reserved word. you cannot use it as a variable name, constant name, etc. there are only 32 reserved
words (keywords) in the c language. All keywords are represented in lower case.
Example:- int weather;
Here, int is a keyword that indicates “Weather” is a variable of type integer. So, we can use int as a Variable name.
IDENTIFIERS IN C
C identifiers represent the name in the c program, for example, variables, functions, arrays, structures, unions,
labels, etc.
An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting
letter should be either an alphabet or an underscore.
Identifier is a collection of alphanumeric characters that begins either with an alphabetical character or an
underscore.
There are 52 alphabetical characters (uppercase and lowercase), underscore character, and ten numerical digits (0-9)
that represent the identifiers.
Example of valid identifiers:-
total, sum, average, _m _, sum_1, etc.
Example of Invalid identifiers:-
• 2sum (starts with a numerical digit)
• int (reserved word)
• char (reserved word)
• m+n (special character, i.e., '+')
CONSTANTS IN C
• A constant is a value or variable that can't be changed in the program,
For example:
- 10, 20, 'a', 3.4, "c programming" etc.
There are two ways to define constant in C
programming.
1. const keyword
2. #define preprocessor
STRINGS IN C
• Strings in c are always represented as an array of characters having null character '0' at the end of the
string.
• This null character denotes the end of the string.
• Strings in c are enclosed within double quotes, while characters are enclosed within single characters.
• The size of a string is a number of characters that the string contains.
Example
• char a[5] = “Acube"; // The compiler allocates the 5 bytes to the 'a' array.
• char a[] = “AlphaAceAcademy"; // The compiler allocates the memory at the run time.
• char a[10] = {‘j’,’a’,’v’,’a’,'0'}; // String is represented in the form of characters.
SPECIAL SYMBOLS IN C
• Some special characters or symbols are used in c, and they have a special meaning which cannot be used for
another purpose.
• Square brackets [ ]: The opening and closing brackets represent the single and multidimensional subscripts.
• Simple brackets ( ): It is used in function declaration and function calling. For example, printf() is a pre-defined
function.
• Curly braces { }: It is used in the opening and closing of the code. It is used in the opening and closing of the
loops.
• Comma (,): It is used for separating for more than one statement and for example, separating function
parameters in a function call, separating the variable when printing the value of more than one variable using a
single printf statement.
• Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we are using the header
file.
• Asterisk (*): This symbol is used to represent pointers and also used as an operator for multiplication.
• Tilde (~): It is used as a destructor to free memory.
• Period (.): It is used to access a member of a structure or a union.
OPERTORS IN C
• Operators is a special symbols used to perform some mathematical or logical functions.
• The data items on which the operators are applied are known as operands.
• Operators are applied between the operands. depending on the number of operands,
Operators are classified as follows:
1. Arithmetic operators (+, -, *, /, %).
2. Relational operators (==, >, <, !=, >=, <=)
3. Logical operators (&&, ||, !)
4. Assignments operators (=, +=, -=, *=, /=, %=)
5. Bitwise operators (&, |, ^, ~, <<, >>)
6. Increment/Decrement operator(++, --)
C COMMENTS
• Comments in C language are used to provide information about lines of code. It is widely used for
documenting code.
• Single-line comment
• Multi-line comment
1. single-line comments in c
In c, a single line comment starts with //.
it starts and ends in the same
2. multi-line comments in c
To comment on multiple lines
at once, they are multi-line
comments.
ESCAPE SEQUENCE IN C
• An escape sequence in C language is a sequence of characters that doesn't represent itself when used
inside string literal or character.
• It is composed of two or more characters starting with backslash . For example: n represents new
line.
FORMAT SPECIFIER IN C
• A format specifier specifies type of
data to be read from keyboard or printed
on screen.
• Types of data available are char, short, int,
long, float, double and long double.
• Format specifiers starts with a precision
sign % followed by a character that
specified the format.
DIFFERENT CASES TO PRINT INPUT AND OUTPUT
ASCII VALUE OF C
• American standard code for information
interexchange or ASCII is a character
encoding standard or a value between 0 and
127, that determines a character variable.
• A character variable does not contain a
character value itself rather the ASCII value
of the character variable.
• The ASCII value represents the character
variable in numbers, and each character
variable is assigned with some number
range from 0 to 127.
• For example, the ASCII value of 'A' is 65.
PROGRAMMING ERRORS IN C
• Error :- Errors are the problems or the faults that occur in the program, which makes the behaviour of the
program abnormal.
• Programming Errors are also known as the bugs or faults, and the process of removing these bugs is known
as debugging.
• These errors are detected either during the time of compilation or execution. Thus, the errors must be
removed from the program for the successful execution of the program.
There are many five types of errors exist in C programming.
• Syntax error.
• Run-time error.
• Linker error.
• Logical error.
• Semantic error.
• Syntax errors:-Syntax errors are also known as the compilation errors as they occurred at the compilation
time.
• Run-time error:- Sometimes the errors exist during the execution-time even after the successful
compilation known as run-time errors.
These errors are vey difficult to find, as the compiler does not point to these errors.
Commonly occurred syntax errors are:
If we miss the parenthesis (}) while writing
the code.
Displaying the value of a variable without its
declaration.
If we miss the semicolon (;) at the end of the
statement.
• Linker error:- Linker error are mainly generated when the executable file of the program is not created.
This can be happened either due to the wrong function prototyping or usage of the wrong header file.
• Logical error:- The logical error is an error that leads to an undesired output. These errors produce the
incorrect output, but they are error free known as logical error.
• Semantic error:- Semantic errors are the errors that occurred when the statements are not
understandable by the complier.
SAMPLE PROGRAMS ON C
// sum of two numbers
OPERATORS IN C
• Operators in c language are the special kind
of symbols that performs certain operations
on the data.
• The collection of operators along with the
data or operands is known as expression.
• C language supports various types of
operators but depends on the number of
operands.
Operators are classified into 3 types:
• Unary Operator.
• Binary Operator.
• Ternary Operator.
UNARY OPERATOR
• Unary operator means an operator can perform
operations on a single operand only.
• That means one operand is enough to perform the
operation is called a unary operator.
• Unary operators are briefly classified into two
types. They are as follows.
1. Increment operators: Increment
operators in c language are again divided into two
types i.e. pre-increment and post-increment.
2. Decrement operators: Decrement
operators in c language are again divided into two
types i.e. pre-decrement and post decrement.
EXAMPLES OF POST INCREMENT/DECREMENT OR PRE
INCREMENT/DECREMENT
BINARY OPERATORS
• Binary operators are those operators that work with two operands.
• A binary operator in c is an operator that takes two operands in an expression or a statement.
Types of Binary operators are
• Arithmetic operators
• Logical operators
• Relational operators
• Bit-wise operators
• Assignment operators
ARITHMETIC OPERATORS
• Arithmetic operators are used to perform mathematical operations. e.g. addition, subtraction,
multiplication, division, modulus.
+ ( Addition ): Used to perform addition of two
operands or variable. If an expression x + y, it will give
a sum of x and y.
– ( Subtraction ): Used to perform subtraction of two
operands or variable. If an expression is x – y, it means
y is subtracted from x.
* ( Multiplication ): Used to perform multiplication of
two operands or variables. If an expression is x * y, it
will give multiplication of x and y.
/ ( Division ): Used to perform division operation of
two operands or variables. If an expression is x / y, it
will give quotient.
% ( Modulus ): Used to perform modulus operation of
two operands or variables. If an expression is x % y, it
will returns remainder.
C PROGRAM TO DEMONSTRATE THE ARITHMETIC
OPERATORS
RELATIONAL OPERATORS
• The relational operators are used to perform the relational operation between two operands or
variables. e.g. comparison, equality check, etc.
• < if an expression is x < y, it will return true if and only if x is less than y, otherwise it will
return false.
• <= if an expression is x <= y, it will return true if and only if x is less than or equal to y,
otherwise it will return false.
• > if an expression is x > y, it will return true if and only if x is greater than y, otherwise it will
return false.
• >= if an expression is x >= y, it will return true if and only if x is greater than or equal to y,
otherwise it will return false.
• == if an expression is x == y, it will return true if and only if x is equal to y, otherwise it will
return false.
• != if an expression is x != y, it will return true if and only if x is not equal to y, otherwise it will
return false.
C PROGRAM TO DEMONSTRATE THE RELATIONAL
OPERATORS.
LOGICAL OPERATOR
• The logical operators are used to perform the logical operation on two operands or variables. e.g. AND
operation, OR operation, NOT operation.
Logical AND ( && ): True, only if all operands /
conditions are true, otherwise false.
• suppose x = 10, and y = 0, then
• x && y will return FALSE.
• If all operands are non-zero, then it will
returns TRUE.
Logical OR ( || ): True, if one or more
operands/conditions are true, otherwise False.
• suppose x = 10, and y = 0, then
• x || y will return TRUE.
• If all operands are zero, then it will returns
FALSE.
Logical NOT ( ! ): True, only if operand is 0.
• suppose y = 0, then
• !y will return TRUE.
• If operand is non-zero, it will returns FALSE.
C PROGRAM TO DEMONSTRATE LOGICAL OPERATORS
BITWISE OPERATORS
• The bitwise operators are used to perform bit-wise operations on operands or variables. e.g. bit-wise
AND operation, bit-wise OR operation, etc.
• Bit-wise and ( & ): The result of bitwise and is 1 if the corresponding bits of two operands is 1,
otherwise the result of corresponding bit evaluated as 0.
• Bit-wise or ( | ): The result of bitwise or is 1 if at least one corresponding bit of two operands is 1,
otherwise the result of the corresponding bit evaluated as 0.
• Bit-wise not ( ~ ): The result of bit-wise not is the one’s complement of the operand. i.e. inverts all bits
of the operand.
• Bit-wise x-or ( ^ ): The result of bit-wise xor is 1 if the corresponding bit of two operands is opposite,
otherwise the result of the corresponding bit evaluated as 0.
• Left shift ( << ): The value of the left operand is shifted to left by the value specified by the right
operand.
• Right shift ( >> ): The value of the left operand is shifted to the right by the value specified by the
right operand.
C PROGRAM TO DEMONSTRATE THE BIT-WISE
OPERATORS
ASSIGNMENT OPERATORS
• The assignment operators are used to perform assignment operation i.e. assigning some values to
variables.
PROGRAM TO DEMONSTRATE THE ASSIGNMENT OPERATORS
TERNARY OPERATORS
• The conditional or ternary operator is used to perform the conditional operation on three operands or
variables. e.g. if the condition is true, it returns first value i.e. true case value, otherwise returns
second value i.e. false case value.
PROGRAM TO DEMONSTRATE THE CONDITIONAL OR
TERNARY OPERATOR
c-introduction.pptx
c-introduction.pptx

More Related Content

Similar to c-introduction.pptx

C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptxAnshSrivastava48
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdfRajb54
 
C prog ppt
C prog pptC prog ppt
C prog pptxinoe
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptANISHYAPIT
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in Cbabuk110
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorialSURBHI SAROHA
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
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).pptxsaivasu4
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programmingMithun DSouza
 
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
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYRajeshkumar Reddy
 

Similar to c-introduction.pptx (20)

C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf67404923-C-Programming-Tutorials-Doc.pdf
67404923-C-Programming-Tutorials-Doc.pdf
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
C language
C languageC language
C language
 
C prog ppt
C prog pptC prog ppt
C prog ppt
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
Data structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in CData structure & Algorithms - Programming in C
Data structure & Algorithms - Programming in C
 
C programming language tutorial
C programming language tutorialC programming language tutorial
C programming language tutorial
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C programming
C programmingC programming
C programming
 
Introduction to C
Introduction to CIntroduction to C
Introduction to C
 
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
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
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)
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDYC LANGUAGE UNIT-1 PREPARED BY MVB REDDY
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
 

Recently uploaded

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

c-introduction.pptx

  • 2. AGENDA • What is c language? • History of c language. • Features of c language. • Applications of c language. • Compilation process in c. • Editors. • Gcc complier. • Basic structure of c program.
  • 3. WHAT IS C LANGUAGE? • C programming is considered as the base for other programming languages, that is why it is known as mother language. • C programming is considered as general purpose programming . • It can be defined by the following ways: 1. Mother language. 2. System programming language. 3. Procedural oriented programming language. 4. Structured programming language. 5. Mid level programming language.
  • 4. HISTORY OF C LANGUAGE • C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of at&t(American telephone & telegraph), located in U.S.A. • Dennis Ritchie is known as founder of c language. • It was developed to be used in UNIX operating system.
  • 5. FEATURES OF C LANGUAGE C is the widely used language. It provides many features that are given below. 1.Simple 2.Machine independent or portable 3.Mid-level programming language 4.Structured programming language 5.Rich library 6.Memory management 7.Speed 8.Pointers 9.Recursion 10.Extensible
  • 6. FEATURES OF C LANGUAGE • SIMPLE :- C IS A SIMPLE LANGUAGE IN THE SENSE IT PROVIDES THE RICH SET OF LIBRARY FUNCTIONS, DATA TYPES, ETC. • MACHINE INDEPENDENT OR PORTABLE :- C IS A MACHINE INDEPENDENT LANGUAGE. • MID – LEVEL PROGRAMMING LANGUAGE :- IT SUPPORTS THE FEATURES OF LOW LEVEL AND HIGH LEVEL LANGUAGES. • STRUCTURED PROGRAMMING LANGUAGE :- IT CAN BREAK THE PROGRAM INTO PARTS USING FUNCTIONS. • RICH LIBRARY :- IT PROVIDES THE LOT OF INBUILT FUNCTION THAT MAKE THE DEVELOPMENT FAST. • MEMORY MANAGEMENT :- IT SUPPORTS THE FEATURE OF DYNAMIC MEMORY ALLOCATION. • SPEED :- THE COMPILATION AND EXECUTION TIME OF C LANGUAGE IS FAST. • POINTER :- WE CAN DIRECTLY INTERACT WITH THE MEMORY BY USING THE POINTERS. • RECURSION :- WE CAN CALL THE FUNCTION WITHIN THE FUNCTION. IT PROVIDES CODE REUSABILITY OF EVERY FUNCTION. • EXTENSIBLE :- IT CAN EASILY ADOPT NEW FEATURES.
  • 7. APPLICATIONS OF C LANGUAGE • Embedded systems. • System applications. • Desktop applications. • Developing browsers. • Databases. • Operating systems. • Compliers.
  • 8. COMPILATION PROCESS OF C • What is compilation? - The compilation is a process of converting the source code into object code. it is done with the help of the compiler. - The c compilation process converts the source code taken as input into the object code or machine code. - The compilation process can be divided into four steps, i.e., pre-processing, compiling, assembling, and linking.
  • 9. Preprocessor - The source code is first passed to the preprocessor, and then the preprocessor expands this code. after expanding the code, the expanded code is passed to the compiler. Complier - The compiler converts this code into assembly code. Assembler - The assembly code is converted into object code by using an assembler. Linker - The linker is to link the object code of our program with the object code of the library files and other files. the output of the linker is the executable file.
  • 10. HOW TO INSTALL C Code Editors :- There are many compilers available for c. • Code blocks • Turbo c++ • Eclipse • Notepad++ • VS code You need to download any one. here, we are going to use vs code. • Install the extension c in vs code. GNU complier collection:- Mingw-w64 - for 32 and 64 bit windows - The mingw-w64 project is a complete runtime Environment for gcc to support binaries native to Windows 64-bit and 32-bit operating systems.
  • 11. BASIC STRUCTURE OF C PROGRAM Header Files ---------- ---------- ---------- Main(){ ----------- ----------- User Defined Functions ----------- ----------- } #include<stdio.h> int main() { Printf(“Hello World”); Printf(“Welcome to C program”); Printf(“Welcome to acube”); }
  • 12. PRINTF() AND SCANF() IN C • The printf() and scanf() functions are used for input and output in c language. • Both functions are inbuilt library functions, defined in stdio.h (header file). printf() function • The printf() function is used for output. it prints the given statement to the console. printf ("format string", argument_list); • The format string can be %d (integer), %c (character), %s (string), %f (float) etc. scanf() function • The scanf() function is used for input. it reads the input data from the console. scanf("format string", argument_list);
  • 13. VARIABLES IN C • A variable is a name of the memory location. • It is used to store data. • Its value can be changed, and it can be reused many times. Syntax to declare a variable: - Syntax - datatype variable name=datatype value; - Examples defining a variable - int f; - int f = 10;
  • 14. BASIC OR PRIMARY DATA TYPES In c, there are four basic data types • int • char • float • double Basic or Primary Data types Floating Point (Float) Character (char) Integer (int) Double (double) Basic Data Types Short Form Description Example Integer int Whole Numbers int age=20; Floating Point float Fractional or Decimal Values float price=10.50; Double double Fractional or Decimal Values double price=10.50230; Character char Character Values char symbol=‘A’;
  • 15. RULES FOR USING VARIABLES IN C • The variable name can contain letters, digits and the underscore( _ ) . Example:- age_20. • The first character of the variable name must be a letter or underscore( _ ). Example:- _abc123, abc_123 • Variable name must not be same as c reserved words or keywords. Example:- int, float, char • No other special symbols or characters (#, &, $, !,@,%) other than underscore(_). Example:- abc@123. • Variables names are the case sensitive. Example:- name and NAME are the two different variables. • It should not contain white spaces. Example:- User name. • The length of the variable name should not be more than 31 characters. - VALID VARIABLE NAMES - INVALID VARIABLE NAMES - int a; - int 2; - int _ab; - int a b; - int a30; - int long;
  • 16. TYPES OF VARIABLES IN C 1. Local Variables: A variable that is declared inside the function or block is called a local variable. Example:- int main() { int a=10; //local variable printf(“the value of a is %d”, a); } 2. Global Variables: A variable that is declared outside the function or block is called a global variable. Example:- int value=20;//global variable void function1() { printf(“%dn”, x); } void function2() { printf(“%dn”, x); } int main(){ function1(); function2(); }
  • 17. • Static Variables: A variable that retains its value between multiple function calls is known as a static variable. It is declared with the static keyword. Example:- #include <stdio.h> void function(){ int x = 20;//local variable static int y = 30;//static variable x = x + 10; y = y + 10; printf("n%d,%d", x, y); } int main() { function(); function(); function(); } • Automatic Variable: All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using the auto keyword. Automatic variables are similar to local variables. Example:- #include <stdio.h> void function() { int x=10;//local variable (also automatic) auto int y=20;//automatic variable } int main() { function(); }
  • 18. • External variables :- - extern is short name for external. - Used when a particular file needs to access a variable from another file. - Declaration and Definition Declaration - int var ; - extern int var;
  • 19. DATATYPES IN C A data type specifies the type of data that a variable can store such as integer, floating, character, etc. There are the following data types in C language.
  • 20. • Primary data types The primary data types in the c programming language are the basic data types. all the primary data types are already defined in the system. Primary data types are also called as built-in data types. The following are the primary data types in c programming language. • Integer data type • Floating Point data type • Double data type • Character data type
  • 21. INTEGER DATATYPE • The integer data type is a set of whole numbers. • Every integer value does not have the decimal value. • we use the keyword "int" to represent integer data type in c. • The integer data type is used with different type modifiers like short, long, signed and unsigned. • The following table provides complete details about the integer data type.
  • 22. FLOATING POINT DATATYPES • Floating-point data types are a set of numbers with the decimal value. • Every floating-point value must contain the decimal value. • The floating-point data type has two variants... • float • double • we use the keyword "float" to represent floating-point data type and "double" to represent double data type in c. • Both float and double are similar but they differ in the number of decimal places. • The float value contains 6 decimal places whereas double value contains 15 or 19 decimal places. • The following table provides complete details about floating- point data types.
  • 23. CHARACTER DATA TYPE • The character data type is a set of characters enclosed in single quotations. • The following table provides complete details about the character data type.
  • 24. The following table provides complete information about all the data types in c programming language.
  • 25. TO CALCULATE THE SIZE OF ALL DATATYPES USING THE 'SIZEOF' OPERATOR sizeof(datatype) operator To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator.
  • 26. TOKENS IN C PROGRAM • Tokens in c is the most important element to be used in creating a program in c. • We can define the token as the smallest individual element in C. • For example, we cannot create a sentence without using words; similarly, we cannot create a program in C without using tokens in C. • Tokens in C is the building block or the basic component for creating a program in c language. • Tokens in C language can be divided into the following categories:
  • 27. KEYWORDS IN C Keywords in C can be defined as the pre-defined or the reserved words having its own importance, and each keyword has its own functionality. A keyword is a reserved word. you cannot use it as a variable name, constant name, etc. there are only 32 reserved words (keywords) in the c language. All keywords are represented in lower case. Example:- int weather; Here, int is a keyword that indicates “Weather” is a variable of type integer. So, we can use int as a Variable name.
  • 28. IDENTIFIERS IN C C identifiers represent the name in the c program, for example, variables, functions, arrays, structures, unions, labels, etc. An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore. Identifier is a collection of alphanumeric characters that begins either with an alphabetical character or an underscore. There are 52 alphabetical characters (uppercase and lowercase), underscore character, and ten numerical digits (0-9) that represent the identifiers. Example of valid identifiers:- total, sum, average, _m _, sum_1, etc. Example of Invalid identifiers:- • 2sum (starts with a numerical digit) • int (reserved word) • char (reserved word) • m+n (special character, i.e., '+')
  • 29. CONSTANTS IN C • A constant is a value or variable that can't be changed in the program, For example: - 10, 20, 'a', 3.4, "c programming" etc. There are two ways to define constant in C programming. 1. const keyword 2. #define preprocessor
  • 30. STRINGS IN C • Strings in c are always represented as an array of characters having null character '0' at the end of the string. • This null character denotes the end of the string. • Strings in c are enclosed within double quotes, while characters are enclosed within single characters. • The size of a string is a number of characters that the string contains. Example • char a[5] = “Acube"; // The compiler allocates the 5 bytes to the 'a' array. • char a[] = “AlphaAceAcademy"; // The compiler allocates the memory at the run time. • char a[10] = {‘j’,’a’,’v’,’a’,'0'}; // String is represented in the form of characters.
  • 31. SPECIAL SYMBOLS IN C • Some special characters or symbols are used in c, and they have a special meaning which cannot be used for another purpose. • Square brackets [ ]: The opening and closing brackets represent the single and multidimensional subscripts. • Simple brackets ( ): It is used in function declaration and function calling. For example, printf() is a pre-defined function. • Curly braces { }: It is used in the opening and closing of the code. It is used in the opening and closing of the loops. • Comma (,): It is used for separating for more than one statement and for example, separating function parameters in a function call, separating the variable when printing the value of more than one variable using a single printf statement. • Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we are using the header file. • Asterisk (*): This symbol is used to represent pointers and also used as an operator for multiplication. • Tilde (~): It is used as a destructor to free memory. • Period (.): It is used to access a member of a structure or a union.
  • 32. OPERTORS IN C • Operators is a special symbols used to perform some mathematical or logical functions. • The data items on which the operators are applied are known as operands. • Operators are applied between the operands. depending on the number of operands, Operators are classified as follows: 1. Arithmetic operators (+, -, *, /, %). 2. Relational operators (==, >, <, !=, >=, <=) 3. Logical operators (&&, ||, !) 4. Assignments operators (=, +=, -=, *=, /=, %=) 5. Bitwise operators (&, |, ^, ~, <<, >>) 6. Increment/Decrement operator(++, --)
  • 33. C COMMENTS • Comments in C language are used to provide information about lines of code. It is widely used for documenting code. • Single-line comment • Multi-line comment 1. single-line comments in c In c, a single line comment starts with //. it starts and ends in the same 2. multi-line comments in c To comment on multiple lines at once, they are multi-line comments.
  • 34. ESCAPE SEQUENCE IN C • An escape sequence in C language is a sequence of characters that doesn't represent itself when used inside string literal or character. • It is composed of two or more characters starting with backslash . For example: n represents new line.
  • 35. FORMAT SPECIFIER IN C • A format specifier specifies type of data to be read from keyboard or printed on screen. • Types of data available are char, short, int, long, float, double and long double. • Format specifiers starts with a precision sign % followed by a character that specified the format.
  • 36. DIFFERENT CASES TO PRINT INPUT AND OUTPUT
  • 37. ASCII VALUE OF C • American standard code for information interexchange or ASCII is a character encoding standard or a value between 0 and 127, that determines a character variable. • A character variable does not contain a character value itself rather the ASCII value of the character variable. • The ASCII value represents the character variable in numbers, and each character variable is assigned with some number range from 0 to 127. • For example, the ASCII value of 'A' is 65.
  • 38. PROGRAMMING ERRORS IN C • Error :- Errors are the problems or the faults that occur in the program, which makes the behaviour of the program abnormal. • Programming Errors are also known as the bugs or faults, and the process of removing these bugs is known as debugging. • These errors are detected either during the time of compilation or execution. Thus, the errors must be removed from the program for the successful execution of the program. There are many five types of errors exist in C programming. • Syntax error. • Run-time error. • Linker error. • Logical error. • Semantic error.
  • 39. • Syntax errors:-Syntax errors are also known as the compilation errors as they occurred at the compilation time. • Run-time error:- Sometimes the errors exist during the execution-time even after the successful compilation known as run-time errors. These errors are vey difficult to find, as the compiler does not point to these errors. Commonly occurred syntax errors are: If we miss the parenthesis (}) while writing the code. Displaying the value of a variable without its declaration. If we miss the semicolon (;) at the end of the statement.
  • 40. • Linker error:- Linker error are mainly generated when the executable file of the program is not created. This can be happened either due to the wrong function prototyping or usage of the wrong header file. • Logical error:- The logical error is an error that leads to an undesired output. These errors produce the incorrect output, but they are error free known as logical error.
  • 41. • Semantic error:- Semantic errors are the errors that occurred when the statements are not understandable by the complier.
  • 42. SAMPLE PROGRAMS ON C // sum of two numbers
  • 43.
  • 44. OPERATORS IN C • Operators in c language are the special kind of symbols that performs certain operations on the data. • The collection of operators along with the data or operands is known as expression. • C language supports various types of operators but depends on the number of operands. Operators are classified into 3 types: • Unary Operator. • Binary Operator. • Ternary Operator.
  • 45. UNARY OPERATOR • Unary operator means an operator can perform operations on a single operand only. • That means one operand is enough to perform the operation is called a unary operator. • Unary operators are briefly classified into two types. They are as follows. 1. Increment operators: Increment operators in c language are again divided into two types i.e. pre-increment and post-increment. 2. Decrement operators: Decrement operators in c language are again divided into two types i.e. pre-decrement and post decrement.
  • 46. EXAMPLES OF POST INCREMENT/DECREMENT OR PRE INCREMENT/DECREMENT
  • 47. BINARY OPERATORS • Binary operators are those operators that work with two operands. • A binary operator in c is an operator that takes two operands in an expression or a statement. Types of Binary operators are • Arithmetic operators • Logical operators • Relational operators • Bit-wise operators • Assignment operators
  • 48. ARITHMETIC OPERATORS • Arithmetic operators are used to perform mathematical operations. e.g. addition, subtraction, multiplication, division, modulus. + ( Addition ): Used to perform addition of two operands or variable. If an expression x + y, it will give a sum of x and y. – ( Subtraction ): Used to perform subtraction of two operands or variable. If an expression is x – y, it means y is subtracted from x. * ( Multiplication ): Used to perform multiplication of two operands or variables. If an expression is x * y, it will give multiplication of x and y. / ( Division ): Used to perform division operation of two operands or variables. If an expression is x / y, it will give quotient. % ( Modulus ): Used to perform modulus operation of two operands or variables. If an expression is x % y, it will returns remainder.
  • 49. C PROGRAM TO DEMONSTRATE THE ARITHMETIC OPERATORS
  • 50. RELATIONAL OPERATORS • The relational operators are used to perform the relational operation between two operands or variables. e.g. comparison, equality check, etc.
  • 51. • < if an expression is x < y, it will return true if and only if x is less than y, otherwise it will return false. • <= if an expression is x <= y, it will return true if and only if x is less than or equal to y, otherwise it will return false. • > if an expression is x > y, it will return true if and only if x is greater than y, otherwise it will return false. • >= if an expression is x >= y, it will return true if and only if x is greater than or equal to y, otherwise it will return false. • == if an expression is x == y, it will return true if and only if x is equal to y, otherwise it will return false. • != if an expression is x != y, it will return true if and only if x is not equal to y, otherwise it will return false.
  • 52. C PROGRAM TO DEMONSTRATE THE RELATIONAL OPERATORS.
  • 53. LOGICAL OPERATOR • The logical operators are used to perform the logical operation on two operands or variables. e.g. AND operation, OR operation, NOT operation. Logical AND ( && ): True, only if all operands / conditions are true, otherwise false. • suppose x = 10, and y = 0, then • x && y will return FALSE. • If all operands are non-zero, then it will returns TRUE. Logical OR ( || ): True, if one or more operands/conditions are true, otherwise False. • suppose x = 10, and y = 0, then • x || y will return TRUE. • If all operands are zero, then it will returns FALSE. Logical NOT ( ! ): True, only if operand is 0. • suppose y = 0, then • !y will return TRUE. • If operand is non-zero, it will returns FALSE.
  • 54. C PROGRAM TO DEMONSTRATE LOGICAL OPERATORS
  • 55. BITWISE OPERATORS • The bitwise operators are used to perform bit-wise operations on operands or variables. e.g. bit-wise AND operation, bit-wise OR operation, etc.
  • 56. • Bit-wise and ( & ): The result of bitwise and is 1 if the corresponding bits of two operands is 1, otherwise the result of corresponding bit evaluated as 0. • Bit-wise or ( | ): The result of bitwise or is 1 if at least one corresponding bit of two operands is 1, otherwise the result of the corresponding bit evaluated as 0. • Bit-wise not ( ~ ): The result of bit-wise not is the one’s complement of the operand. i.e. inverts all bits of the operand. • Bit-wise x-or ( ^ ): The result of bit-wise xor is 1 if the corresponding bit of two operands is opposite, otherwise the result of the corresponding bit evaluated as 0. • Left shift ( << ): The value of the left operand is shifted to left by the value specified by the right operand. • Right shift ( >> ): The value of the left operand is shifted to the right by the value specified by the right operand.
  • 57. C PROGRAM TO DEMONSTRATE THE BIT-WISE OPERATORS
  • 58. ASSIGNMENT OPERATORS • The assignment operators are used to perform assignment operation i.e. assigning some values to variables.
  • 59. PROGRAM TO DEMONSTRATE THE ASSIGNMENT OPERATORS
  • 60. TERNARY OPERATORS • The conditional or ternary operator is used to perform the conditional operation on three operands or variables. e.g. if the condition is true, it returns first value i.e. true case value, otherwise returns second value i.e. false case value.
  • 61. PROGRAM TO DEMONSTRATE THE CONDITIONAL OR TERNARY OPERATOR