Chapter2
Chapter2
Instructor
Prof. S.S Pathare
K. K. Wagh Polytechnic,
Nashik
Course Outcome
After completing this course a learner will able to,
Functions :
printf() - This function is used to print the character, string, float,
integer, octal and hexadecimal values onto the output screen
scanf() - This function is used to read a character, string, numeric
data from keyboard.
getc() - It reads character from file
gets() - It reads line from keyboard
conio.h header file
The conio.h header file used in C programming language contains
functions for console input/output.
Functions :
clrscr() - This function is used to clear the output screen.
getch() - It reads character from keyboard
getche() -It reads character from keyboard and echoes to o/p screen
textcolor() -This function is used to change the text color
textbackground() -This function is used to change text background
Character set
every language contains a set of characters used to construct words, statements, etc.,C language also has a
set of characters which include alphabets, digits, and special symbols.
C language support total 256 characters
C language character set contains the following set of characters.
Alphabets
C language supports all the alphabets from the English language. Lower and upper case letters together
support 52 alphabets.
lower case letters - a to z UPPER CASE LETTERS - A to Z
Digits
C language supports 10 digits which are used to construct numerical values in C language.
Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
C language supports a rich set of special symbols that include symbols to perform mathematical operations, to
check conditions, white spaces, backspaces, and other special symbols. Special Symbols - ~ @ # $ % ^ & * ( ) _
- + = { } [ ] ; : ' " / ? . > , < \ etc.
Token
TOKEN is the smallest unit in a 'C' program. It is each and every word and punctuation that you come
across in your C program.
The compiler breaks a program into the smallest possible units (tokens) and proceeds to the various stages
of the compilation.
A token is divided into six different types, viz, Keywords, Operators, Strings, Constants, Special Characters,
and Identifiers
Keywords
Keywords have fixed meanings, and the meaning cannot be changed.
They act as a building block of a 'C' program.
There are a total of 32 keywords in 'C'.
Keywords are written in lowercase letters.
Identifier
An identifier is nothing but a name assigned to an element in a program.
Example, name of a variable, function, etc. Identifiers are the user-
defined names consisting of 'C' standard character set.
As the name says, identifiers are used to identify a particular element in
a program. Each identifier must have a unique name.
Uppercase and lowercase characters are treated differently
Following rules must be followed for identifiers:
The first character must always be an alphabet or an underscore.
It should be formed using only letters, numbers, or underscore.
A keyword cannot be used as an identifier.
Constant
constants, as the name itself suggests, are fixed values i.e. they cannot
change their value during program run once they are defined.
Syntax of Constant in C Programming-
const data_type variable_name = value;
Using #define pre-processor #define pi=3.14
Various Types of Constants in C Language-
Integer constants: For example, const int value = 400;
Floating constants: For example, const float pi = 3.14;
Character constants: For example, const char gender = ‘f’;
String constants: For example, const char name[] = ‘‘DataFlair’’;
Octal constants: The number system which consists only 8 digits, from 0 to 7 is called the
octal number system. The constant octal values can be declared as, const int oct = 040;
Hexadecimal constants: The number system which consists of 16 digits, from 0 to 9 and
alphabets ‘a’ to ‘f’ is called hexadecimal number system. The constant hexadecimal values can
be declared as, const int hex = 0x40;
Data Type
A data type specifies the type of data that a variable can store
Each data type requires different amounts of memory and has some
specific operations which can be performed over it.
Following are the examples of some very common data types used in C:
char: The most basic data type in C. It stores a single character and
requires a single byte of memory in almost all compilers.
int: As the name suggests, an int variable is used to store an integer.
float: It is used to store decimal numbers (numbers with floating point
value) with single precision.
double: It is used to store decimal numbers (numbers with floating
point value) with double precision.
Data Type
Declaring variables
C variable is a named location in a memory where a program can
manipulate the data. This location is used to hold the value of the
variable.
The value of the C variable may get change in the program.
C variable might be belonging to any of the data type like int,
float, char etc.
Syntax:
datatype variable_list;
We can also provide values while declaring the variables as given below:
int a=10,b=20;//declaring 2 variable of integer type
float f=20.8;
char c='A';
Operators
Operators as symbols that help us to perform specific
mathematical and logical computations on operands. In other
words, we can say that an operator operates the operands.
Main types of operator
A unary operator is an operator that operates on a single
operand. An operand can be a value or an expression.
a binary operator operates on two operands
a ternary operator operates on three operands
Arithmetic operators
These are the operators used to perform arithmetic/mathematical
operations on operands.
Increment / Decrement operator
(++ / --)
Types :
Pre-increment- Value of input variable increased by one and incremented value
assigned to output variable
Let a=5 b=++a then a=6 and b=6
Syntax:
scanf (“format string”, &arg1, &arg2, …..);