SlideShare a Scribd company logo
1 of 26
UNIT- I
Introduction To C:
It has been developed by Dennis Ritchie at Bell
laboratories in the year of 1972.
C is a middle level general purpose language
C is structured Language
The C Declarations:
A Program is a set of statements for a specific
task, which will be executed in a sequential form
The C Character Set:
The characters used to form words, numbers and
expressions.
The characters in C are Classified into the following:
1. Letters – (Capital A – Z , Small a – z)
2. Digits – ( 0 - 9 )
3. White Spaces – (Blank space, Vertical tab, New Line)
4. Special Characters – ( , . ; : ‘ “ ! /  ~ - $ ? * & ^ % # @ { } [
] ( ) + = _ < > )
Delimiters:
: Colon  Useful for label
; Semi Colon  Terminates statements
( ) Parenthesis  Used in expression and function
[ ] Square Bracket  Used for array declaration
{ } Curly Brace  Scope of Statements
# Hash  Preprocessor directives
, Comma  Variable separator
The C Keywords:
The C Keywords are reserved words by the
compiler
All the C Keywords have been assigned some
fixed meaning
So The C keywords cannot be used as variable
name.
Ex:
Auto double int struct
Break else long switch
Case enum union unsigned
Const do goto sizeof
If static while main
Identifiers:
 Identifiers are names of variables, functions and
arrays.
 Lower case letters are preferred, the upper case
letters are also permitted
 ( _ ) under score symbol can be used as an identifier
Ex:
# define N 10
# define a 15
Constants: ( 8 mark)
 The constants in C are applicable to the values, which
do not change during the execution of a program.
They are classified into the following group:
User Defined Identifiers
A. Numeric Constants:
i) Integer Constants:
- These are the sequence of numbers from 0 to 9 without
decimal points or fractional part or any other symbols
- It requires 2 bytes or maximum 4 bytes
- It could either +ve , -ve or zero
Ex: 10, 20, +30, -25, 0
C Constants
Character Constants
Numeric Constants
Integer Constants
Real Constants
Single Character Constants
String Constants
ii) Real Constants:
- Real constants are often known as floating point
constants
- Real constants can be written in exponential
notation, which contains a fractional part and a
exponential part
Ex: 2.5, 5.32, 3.14 etc.
B. Character Constant:
i) Single Character Constants:
A character constant is a single character
enclosed with single quotes.
It includes single digit, single character, white
space
Ex: ‘a’ , ‘7’ , ‘ ’ etc.
ii) String Constants:
 Sting constants are sequence of characters
enclosed with a double quote marks.
Ex: “Heber” , “Basil” , “888” , “a”
Variables:
 A variable is a data name used for storing a data
value.
 Its value may be changed during the execution of
the program
Ex: a , height, sum, avg
Rules for defining variables:
1) They must begin with a character without spaces
but underscore is permitted
2) Generally most compilers support 8 characters
length
Maximum length of a variable upto 31 characters
3) The Variable should not be a C Keywords
4) The variable names may be combination of
uppercase and lowercase characters
Ex: suM, AVg
5) The Variable name should not start with a digit
Data Types: ( 8 mark or 15 mark )
The C compiler supports a variety of data types.
They are:
1) Integer Data type:
a) Integer, short and Long:
Short integer requires 2 bytes and the long integers
requires 4 bytes
Name Range Storage
Size
Format
String
Example
Short
integer
-32,768 to +32,767 2 bytes %d or %I Int a=2;
Short int b=2;
Long
Integer
-2,147,483,648 to 2,147,483,647 4 bytes %ld Long b;
Long int c;
Signed
Integer
-32,768 to +32,767 2 bytes %d or %i Int a=5;
Signed int d;
Un
signed
integer
0 to 65535 2 bytes %u Unsigned
integer c=7;
Signed
Char
-127 to 127 1 byte %c Char c;
Unsign
ed char
0 to 255 1 byte %c Unsigned char
c;
float -3.4e38 to 3.4e38 4 bytes %f Float d;
Double -1.7e-308 to 1.7e+308 8 bytes %lf Double d;
Long double
x;
Declaring variables:
-The Variables must be declared before they are
used in the program
Declaration Provide two things:
1) Compiler Obtains the variable name
2) It tells the compiler data type of the variable an
allocating memory
Syntax: Data_type Variable_Name;
Ex: int age; char c;
int b, c; float d;
Data types:
Char , signed char , Unsigned char , int , signed int ,
unsigned int , unsigned short int , signed long int ,
unsigned long int , float , double , long double
Initializing Variables:
Variables can be assigned or initialized using an
assignment operator ‘=‘
Declaration & initialization can be done in the same
line.
Syntax: Data_type Variable_name = Constant;
Ex: int a=10; float b=2.17;
int a=b=c=20;
Type Conversion:
Sometimes the programmer needs the result in
certain data type
Ex: division of 5 with 2 should return float value
Ex:
# include <stdio.h>
# include <conio.h>
main()
{
printf(“Two integers (5 & 2) : %d ”, 5/2);
printf(“Two integers (5 & 2) : %f ”, (float) 5/2);
getch();
}
Output: Two integers (5 & 2) : 2
Two integers (5 & 2) : 2.5
2. Operators & Expressions:
An Operator indicates an operation to be performed on
data they yield a value.
C Provides 4 Classes of operators:
i) Arithmetic Operators ii) Relational Operators
ii) Logical Operators iii) Bitwise Operators
Types of Operators:
Types of Operators Symbolic Representation
Arithmetic Operators + , - , * , / and %
Relational Operators > , < , >= , <= , = = , and !=
Increment & Decrement Operator ++ and - -
Assigned Operators =
Bitwise Operators & , | , ^ , >> , << and ~
Comma Operator ,
Conditional Operator ? :
Logical Operators && , || , !
Priority Of Operators:
( ) [ ] -> .
+ - ++ - - ! ~ * &
* / %
<< >>
< <= > >=
= = !=
&
^
| Ex:
X = 5 * 4 + 8 / 2
1 2
3
i) Comma & Conditional Operator:
a)Comma operator is used to separate two or more
variable or expressions
Ex: int a, b, c; a=10, b=20, c=a+b;
Ex:
#include <stdio.h>
#include<conio.h>
main()
{
clrscr();
printf(“Addition = %d t Subtraction = %d”, 10+20, 5-2);
getch();
} Output:
Addition = 30 Subtraction = 3
b) Conditional Operator:
The conditional operator contains a condition
followed by two statements or values.
If the condition is true the first statement is
executed otherwise the second statement is
executed
The Conditional Operator ? And : are sometimes
called ternary operators
Syntax: Condition ? (expression1) : (expression2);
Ex: main()
{
clrscr();
3 > 2 ? printf(“3 is big”) : printf(“2 is big”);
getch();
}
Output:
3 is big
ii) Arithmetic Operators:
Two types of arithmetic operators:
a) Binary Operators b) Unary Operators
a) Binary operator:
Binary arithmetic operators are used for numerical
calculations between the two constant values.
+  Addition -  subtraction
*  Multiplication /  Division
%  Modular Division (Remainder)
Ex:
b) Unary Operators:
-  Minus ++  Increment
- -  Decrement &  Address operator
Size of  gives the size of variables
a) Minus ( - ):
Indicates the algebraic sign of a value
Ex: int x = -10; int y = -25;
b) Increment (++) and Decrement (--) Operators:
The operator ++ adds one to its operand
The operator - - subtract one from its operand
Ex:
main()
{
int a, b, x=10, y=20;
clrscr();
a=x*y++;
b=x*y;
printf(“a= %d t b=%d”, a,
b);
getch()
}
Output: a=200 b=210
Ex:
main()
{
int a, z, x=10, y=20;
clrscr();
z=x*++y;
a=x*y;
printf(“a= %d t b=%d”);
getch()
}
Output: 210 210
c) Sizeof () and & operator:
Sizeof()  gives the size of the
variable
&  prints address of the
variable in the memory
Ex: main()
{ int a;
clrscr();
scanf(“%d”,&a);
printf(“size of (a) =%d”,
sizeof(a));
printf(“Address of a = %u”,
&a);
getch(); }
iii) Relational Operators:
These operators provide the relationship between the
two expressions
If the relation is true then it returns a value 1 otherwise 0
for false relation
Ex:
main()
{
clrscr();
printf(“n 10!=10 : %d”, 10!=10);
printf(“n 10==10 : %d”, 10==10);
printf(“n 10>=10 : %d”, 10>=10);
printf(“n 10<=10 : %d”, 10<=10);
printf(“n 10!=9 : %d”, 10!=9);
getch()
}
Output:
10!=10 : 0
10==10 : 1
10>=10 : 1
10<=10 : 1
10!=9 : 1
iv) Logical Operators:
 The logical relationship between the two expressions are
checked
 Using these operators two expressions can be joined
 After checking it provides true(1) or false(0) status
Ex:
main()
{
clrscr();
printf(“n (5>3) && (5<10) : %d”, (5>3) && (5<10));
printf(“n (5>20) || (5<10) : %d”, (5>20) || (5<10));
printf(“n !(7==7) : %d”, !(7==7));
getch()
}
Output:
5>3 && 5<10 : 1
5>20 || 5<10 : 1
!(7==7) : 0
iv) Bitwise Operators:
 C support 6 bitwise operators
Operators Meaning
>> Right shift
<< Left shift
^ Bitwise XOR (Exclusive OR)
~ One’s Complement
& Bitwise AND
| Bitwise OR
Ex:
main()
{
int x, y;
clrscr();
printf(“Read the value from keyboard:”);
scanf(“%d”, %x);
x>>=2;
y=x;
printf(“The left shifted data is =%d”, y);
getch();
}
Output:
Read the value from Keyboard: 8
0 0 0 0 1 0 0 0
The Right shifted data is = 2
0 0 0 0 0 0 1 0
AND: OR: XOR:
00 = 0 00 = 0 00 = 0
01 = 0 01 = 1 01 = 1
10 = 0 10 = 1 10 = 1
11 = 1 11 = 1 11 = 0
Ex:
main()
{
int x, y, z;
clrscr();
printf(“Read the x and y values from keyboard:”);
scanf(“%d%d”, &x, &y);
z=x&y;
printf(“The Answer after AND operation =%d”, z);
getch();
}
Output:
Read the x and y values from Keyboard:
8
4
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0
The Answer after AND operation = 0

More Related Content

What's hot (20)

CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
CP Handout#4
CP Handout#4CP Handout#4
CP Handout#4
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
C Programming
C ProgrammingC Programming
C Programming
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
C++
C++C++
C++
 
C language basics
C language basicsC language basics
C language basics
 
Getting Started with C++
Getting Started with C++Getting Started with C++
Getting Started with C++
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
C language basics
C language basicsC language basics
C language basics
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Overview of c++ language
Overview of c++ language   Overview of c++ language
Overview of c++ language
 
Getting started in c++
Getting started in c++Getting started in c++
Getting started in c++
 
C Programming
C ProgrammingC Programming
C Programming
 
02 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_0202 iec t1_s1_oo_ps_session_02
02 iec t1_s1_oo_ps_session_02
 
Programming C Language
Programming C LanguageProgramming C Language
Programming C Language
 

Similar to Unit i intro-operators

Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxKrishanPalSingh39
 
introductory concepts
introductory conceptsintroductory concepts
introductory conceptsWalepak Ubi
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubeykiranrajat
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic Manzoor ALam
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdfMaryJacob24
 

Similar to Unit i intro-operators (20)

Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
C programming language
C programming languageC programming language
C programming language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit DubeyMCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey
 
C material
C materialC material
C material
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
C program
C programC program
C program
 
C programming
C programmingC programming
C programming
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Unit i intro-operators

  • 1. UNIT- I Introduction To C: It has been developed by Dennis Ritchie at Bell laboratories in the year of 1972. C is a middle level general purpose language C is structured Language The C Declarations: A Program is a set of statements for a specific task, which will be executed in a sequential form The C Character Set: The characters used to form words, numbers and expressions.
  • 2. The characters in C are Classified into the following: 1. Letters – (Capital A – Z , Small a – z) 2. Digits – ( 0 - 9 ) 3. White Spaces – (Blank space, Vertical tab, New Line) 4. Special Characters – ( , . ; : ‘ “ ! / ~ - $ ? * & ^ % # @ { } [ ] ( ) + = _ < > ) Delimiters: : Colon  Useful for label ; Semi Colon  Terminates statements ( ) Parenthesis  Used in expression and function [ ] Square Bracket  Used for array declaration { } Curly Brace  Scope of Statements # Hash  Preprocessor directives , Comma  Variable separator
  • 3. The C Keywords: The C Keywords are reserved words by the compiler All the C Keywords have been assigned some fixed meaning So The C keywords cannot be used as variable name. Ex: Auto double int struct Break else long switch Case enum union unsigned Const do goto sizeof If static while main
  • 4. Identifiers:  Identifiers are names of variables, functions and arrays.  Lower case letters are preferred, the upper case letters are also permitted  ( _ ) under score symbol can be used as an identifier Ex: # define N 10 # define a 15 Constants: ( 8 mark)  The constants in C are applicable to the values, which do not change during the execution of a program. They are classified into the following group: User Defined Identifiers
  • 5. A. Numeric Constants: i) Integer Constants: - These are the sequence of numbers from 0 to 9 without decimal points or fractional part or any other symbols - It requires 2 bytes or maximum 4 bytes - It could either +ve , -ve or zero Ex: 10, 20, +30, -25, 0 C Constants Character Constants Numeric Constants Integer Constants Real Constants Single Character Constants String Constants
  • 6. ii) Real Constants: - Real constants are often known as floating point constants - Real constants can be written in exponential notation, which contains a fractional part and a exponential part Ex: 2.5, 5.32, 3.14 etc. B. Character Constant: i) Single Character Constants: A character constant is a single character enclosed with single quotes. It includes single digit, single character, white space Ex: ‘a’ , ‘7’ , ‘ ’ etc.
  • 7. ii) String Constants:  Sting constants are sequence of characters enclosed with a double quote marks. Ex: “Heber” , “Basil” , “888” , “a” Variables:  A variable is a data name used for storing a data value.  Its value may be changed during the execution of the program Ex: a , height, sum, avg Rules for defining variables: 1) They must begin with a character without spaces but underscore is permitted 2) Generally most compilers support 8 characters length
  • 8. Maximum length of a variable upto 31 characters 3) The Variable should not be a C Keywords 4) The variable names may be combination of uppercase and lowercase characters Ex: suM, AVg 5) The Variable name should not start with a digit Data Types: ( 8 mark or 15 mark ) The C compiler supports a variety of data types. They are: 1) Integer Data type: a) Integer, short and Long: Short integer requires 2 bytes and the long integers requires 4 bytes
  • 9. Name Range Storage Size Format String Example Short integer -32,768 to +32,767 2 bytes %d or %I Int a=2; Short int b=2; Long Integer -2,147,483,648 to 2,147,483,647 4 bytes %ld Long b; Long int c; Signed Integer -32,768 to +32,767 2 bytes %d or %i Int a=5; Signed int d; Un signed integer 0 to 65535 2 bytes %u Unsigned integer c=7; Signed Char -127 to 127 1 byte %c Char c; Unsign ed char 0 to 255 1 byte %c Unsigned char c; float -3.4e38 to 3.4e38 4 bytes %f Float d; Double -1.7e-308 to 1.7e+308 8 bytes %lf Double d; Long double x;
  • 10. Declaring variables: -The Variables must be declared before they are used in the program Declaration Provide two things: 1) Compiler Obtains the variable name 2) It tells the compiler data type of the variable an allocating memory Syntax: Data_type Variable_Name; Ex: int age; char c; int b, c; float d; Data types: Char , signed char , Unsigned char , int , signed int , unsigned int , unsigned short int , signed long int , unsigned long int , float , double , long double
  • 11. Initializing Variables: Variables can be assigned or initialized using an assignment operator ‘=‘ Declaration & initialization can be done in the same line. Syntax: Data_type Variable_name = Constant; Ex: int a=10; float b=2.17; int a=b=c=20; Type Conversion: Sometimes the programmer needs the result in certain data type Ex: division of 5 with 2 should return float value
  • 12. Ex: # include <stdio.h> # include <conio.h> main() { printf(“Two integers (5 & 2) : %d ”, 5/2); printf(“Two integers (5 & 2) : %f ”, (float) 5/2); getch(); } Output: Two integers (5 & 2) : 2 Two integers (5 & 2) : 2.5
  • 13. 2. Operators & Expressions: An Operator indicates an operation to be performed on data they yield a value. C Provides 4 Classes of operators: i) Arithmetic Operators ii) Relational Operators ii) Logical Operators iii) Bitwise Operators Types of Operators: Types of Operators Symbolic Representation Arithmetic Operators + , - , * , / and % Relational Operators > , < , >= , <= , = = , and != Increment & Decrement Operator ++ and - - Assigned Operators = Bitwise Operators & , | , ^ , >> , << and ~ Comma Operator , Conditional Operator ? : Logical Operators && , || , !
  • 14. Priority Of Operators: ( ) [ ] -> . + - ++ - - ! ~ * & * / % << >> < <= > >= = = != & ^ | Ex: X = 5 * 4 + 8 / 2 1 2 3
  • 15. i) Comma & Conditional Operator: a)Comma operator is used to separate two or more variable or expressions Ex: int a, b, c; a=10, b=20, c=a+b; Ex: #include <stdio.h> #include<conio.h> main() { clrscr(); printf(“Addition = %d t Subtraction = %d”, 10+20, 5-2); getch(); } Output: Addition = 30 Subtraction = 3
  • 16. b) Conditional Operator: The conditional operator contains a condition followed by two statements or values. If the condition is true the first statement is executed otherwise the second statement is executed The Conditional Operator ? And : are sometimes called ternary operators Syntax: Condition ? (expression1) : (expression2); Ex: main() { clrscr(); 3 > 2 ? printf(“3 is big”) : printf(“2 is big”); getch(); } Output: 3 is big
  • 17. ii) Arithmetic Operators: Two types of arithmetic operators: a) Binary Operators b) Unary Operators a) Binary operator: Binary arithmetic operators are used for numerical calculations between the two constant values. +  Addition -  subtraction *  Multiplication /  Division %  Modular Division (Remainder) Ex: b) Unary Operators: -  Minus ++  Increment - -  Decrement &  Address operator Size of  gives the size of variables
  • 18. a) Minus ( - ): Indicates the algebraic sign of a value Ex: int x = -10; int y = -25; b) Increment (++) and Decrement (--) Operators: The operator ++ adds one to its operand The operator - - subtract one from its operand Ex: main() { int a, b, x=10, y=20; clrscr(); a=x*y++; b=x*y; printf(“a= %d t b=%d”, a, b); getch() } Output: a=200 b=210
  • 19. Ex: main() { int a, z, x=10, y=20; clrscr(); z=x*++y; a=x*y; printf(“a= %d t b=%d”); getch() } Output: 210 210 c) Sizeof () and & operator: Sizeof()  gives the size of the variable &  prints address of the variable in the memory Ex: main() { int a; clrscr(); scanf(“%d”,&a); printf(“size of (a) =%d”, sizeof(a)); printf(“Address of a = %u”, &a); getch(); }
  • 20. iii) Relational Operators: These operators provide the relationship between the two expressions If the relation is true then it returns a value 1 otherwise 0 for false relation Ex: main() { clrscr(); printf(“n 10!=10 : %d”, 10!=10); printf(“n 10==10 : %d”, 10==10); printf(“n 10>=10 : %d”, 10>=10); printf(“n 10<=10 : %d”, 10<=10); printf(“n 10!=9 : %d”, 10!=9); getch() } Output: 10!=10 : 0 10==10 : 1 10>=10 : 1 10<=10 : 1 10!=9 : 1
  • 21. iv) Logical Operators:  The logical relationship between the two expressions are checked  Using these operators two expressions can be joined  After checking it provides true(1) or false(0) status Ex: main() { clrscr(); printf(“n (5>3) && (5<10) : %d”, (5>3) && (5<10)); printf(“n (5>20) || (5<10) : %d”, (5>20) || (5<10)); printf(“n !(7==7) : %d”, !(7==7)); getch() } Output: 5>3 && 5<10 : 1 5>20 || 5<10 : 1 !(7==7) : 0
  • 22. iv) Bitwise Operators:  C support 6 bitwise operators Operators Meaning >> Right shift << Left shift ^ Bitwise XOR (Exclusive OR) ~ One’s Complement & Bitwise AND | Bitwise OR
  • 23. Ex: main() { int x, y; clrscr(); printf(“Read the value from keyboard:”); scanf(“%d”, %x); x>>=2; y=x; printf(“The left shifted data is =%d”, y); getch(); }
  • 24. Output: Read the value from Keyboard: 8 0 0 0 0 1 0 0 0 The Right shifted data is = 2 0 0 0 0 0 0 1 0 AND: OR: XOR: 00 = 0 00 = 0 00 = 0 01 = 0 01 = 1 01 = 1 10 = 0 10 = 1 10 = 1 11 = 1 11 = 1 11 = 0
  • 25. Ex: main() { int x, y, z; clrscr(); printf(“Read the x and y values from keyboard:”); scanf(“%d%d”, &x, &y); z=x&y; printf(“The Answer after AND operation =%d”, z); getch(); }
  • 26. Output: Read the x and y values from Keyboard: 8 4 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 The Answer after AND operation = 0