PPS Notes Unit-II
PPS Notes Unit-II
ATHEMATIC EXPRESSIONS
Expressions: An expression is a sequence of operands and operators that reduces to a single value.
Operator: An operator is a syntactical token that requires an action to be taken.
Operand: An operand is an object on which the operation is performed. Simply operand is an object
which receives operation from operator.
Expressions can be of two types: simple expressions and complex expressions.
Simple Expression: A simple expression contains only one operator. Ex: 2+7
Complex Expression: A compound expression contains more than one operator. Ex: 2+7*6
OPERATORS IN C-LANGUAGE:
Operators are the foundation for any programming language. The functionality of C programming
language is incomplete without the use of operators.
The operator can be defined as symbols that performs a specific mathematical or logical computations on
operands. In other words operator operates on the operands.
In C, Operators are broadly categorized into 3 – types: i) Unary Operators ii) Binary Operator and
iii)Ternary Operator
This broad categorization is done based on the number of operands the operator will use in exhibiting its
functionality.
i) Unary Operators: Operators of this type, operates or works with a single operand. Hence the
name unary operators. For example: (++, --).
ii) Binary Operators: Operators of this type, operates or works with a two operands. Hence the name
binary operators. For example: (+, -, *./).
iii) Ternary Operators: Operators of this type, operates or works with a three operands. Hence the
name ternary operators. For example: (?:).
Based on the above criterion in mind, Operators are categorized into the following categories:
a) Arithmetic Operators:
b) Relational Operators:
c) Logical Operators
d) Bitwise Operators
e) Assignment Operators
f) Increment and Decrement Operators
g) Conditional Operator
h) Other Operators
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
a) Arithmetic Operators:
Arithmetic operators are used to perform arithmetic/mathematical operations on operands.
b) Relational Operators:
Relational operators are used for comparison of two operand values. All of the relational operators are
binary operators. They need two operands to perform their functionality. They are as follows:
int main()
{
int a=10, b=4;
if (a > b)
printf("a is greater than b\n");
else printf("a is less than or equal to b\n");
if (a >= b)
printf("a is greater than or equal to b\n");
else printf("a is lesser than b\n");
if (a < b)
printf("a is less than b\n");
else printf("a is greater than or equal to b\n");
if (a <= b)
printf("a is lesser than or equal to b\n");
else printf("a is greater than b\n");
if (a == b)
printf("a is equal to b\n");
else printf("a and b are not equal\n");
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
if (a != b)
printf("a is not equal to b\n");
else printf("a is equal b\n");
return 0;
}
Output:
a is greater than b
a is greater than or equal to b
a is greater than or equal to b
a is greater than b
a and b are not equal
a is not equal to b
c) Logical Operators:
Logical operators are used to perform logical operations such as Logical AND, Logical OR and Logical
NOT. They are used to combine two or more conditions/constraints or to complement the evaluation of
the original condition in consideration. They are as follows:
if (a>b || c==d)
printf("a is greater than b OR c is equal to d\n");
else printf("Neither a is greater than b nor c is equal to d\n");
if (!a)
printf("a is zero\n");
else printf("a is not zero");
return 0;
}
Output:
AND condition not satisfied
a is greater than b OR c is equal to d
a is not zero
d) Bitwise Operator:
Bitwise operators work at bit level of the given operands. There are 6-different types of bitwise operators:
& (bitwise AND operator):
o This operator takes two numbers as operands and does AND on every bit of two numbers.
o The result of AND is 1 only if both bits are 1.
| (bitwise OR operator):
o This operator takes two numbers as operands and does OR on every bit of two numbers.
o The result of OR is 1 if any of the two bits is 1.
Examples:
a b a&b a|b a^b ~a
0 0 0 0 1 1
0 1 0 1 0 1
1 0 0 1 0 0
1 1 1 1 1 0
a = 5(00000101), b = 9(00001001)
a&b = 00000001
a|b = 00001101
a^b = 00001100
~a = 11111010
b<<1 = 00010010
b>>1 = 00000100
2. The left-shift and right-shift operators are equivalent to multiplication and division by 2 respectively.
For example: if x=18 then x<<1 = 36, x>>1 = 9
#include<stdio.h>
int main()
{
int x = 18;
printf ("x << 1 = %d\n", x << 1);
printf ("x >> 1 = %d\n", x >> 1);
return 0;
}
Output:
36 9
3. The & operator can be used to quickly check if a number is odd or even.
For example: The value of expression (x & 1) would be non-zero only if x is odd, otherwise the value
would be zero.
#include<stdio.h>
int main()
{
int x = 19;
(x & 1)? printf("Odd"): printf("Even");
return 0;
}
Output:
Odd
e) Assignment Operators:
The assignment operator (=) evaluates the operand on the right side of the operator (=) and places the
value in the variable on the left.
The value on the right side must be of the same data-type of variable on the left side otherwise the
compiler will raise an error.
Types of Assignment:
There are three different types of assignments possible using the same operator (=).
1. Simple assignment: This type of statement will have only one assignment operator in it. The right
side value or the result will be assigned to the left-side variable.
Example: a=10; //Here variable a will hold 10 after assignment.
2. Multiple assignment: This type of statement will have multiple assignment statements in it.
Example: a=b=c=10; // Here value 10 will be assigned to a, b, c variables
3. Compound assignment: It is a shorthand notation for a simple assignment. It requires the left
operator to be repeated as a part of the right expression. There are five compound assignment
operators listed in the following table.
Operator Example Equivalent Statement
+= c += 7 c=c+7
-= c -= 8 c=c–8
*= c *= 10 c = c * 10
/= c /= 5 c=c/5
%= c %= 5 c=c%5
Prefix: In this form, the operator is place before the variable, and the variable’s value will be
incremented by 1 before the expression evaluation. Hence the name prefix.
Syntax: a=++b; /*here first the ‘a’ value will be incremented by 1 and then will be
initialized to ‘b’ */
#include<stdio.h>
int main(void)
{
int a,b=7;
system("cls");
a=++b; //postfix increment
printf("\n%d %d", a, b);
a=--b; //postfix decrement
printf("\n%d %d", a, b);
return 0;
}
Output:
88
77
g) Conditional Operator:
Conditional operator also known as ternary operator.
It is the only operator in C, which takes three operands in its operation.
The (?:) token is used to form this operator.
h) Other Operators:
C supports the following set of special operators:
& (Address Operator) The address operator is used get the address of an operand.
It is a unary operator, it requires only on operand.
When used with the operand, it returns the address of that operand’s
memory location.
* (Indirection Operator) To access the value from the given address, the * operator is used.
Generally it deal with pointer, where to get the value from a pointer
this operator is used.
It is also a unary operator, requires only one operand to perform its
functionality.
, (Comma Operator) This operator does not show any operations on the operands, rather it
is used to separate the expressions which are appearing in the same
line.
Like regular use, the comma operator is used like a separator.
Example: int a,b,c;
j=(i=12,i+20);
sizeof() Operator This operator is used to know the memory size of the operand
supplied.
As it is a unary operator, it operates on single operand.
Syntax: sizeof(datatype/variable);
Example: sizeof(a);
sizeof(int);
. and (Member access The . (dot) and operators are used to access the members of a
Operators: structure (directly or indirectly).
Example: 2+3*4 = ?
In precedence table operator * is having higher precedence than operator +, hence the * will be
evaluated first and then +, so the value is 14 (see the following precedence table).
Associativity:
Associativity can be left-to-right or right-to-left.
Left-to-right associativity evaluates the expression by starting on the left and moving to the right.
Right-to-left associativity evaluates the expression by starting on the right and moving to the left.
Remember, associativity is used only when there are operators with same precedence level in occur in a
complex expression.
Associativity Rule
Example:
1. 3*8/4 is 6
2. 2+3%2*4 is 6
3. 3*8/4%4*5 is 10
I. Simple if – Statement:
In C, the simplest form of decision making is the if – statement.
If statement will have a condition helpful in making the decision.
If the condition is true then the statement-block will be executed.
If the condition is false it does not do anything (or the statements block is skipped). Simply the
simple form of if statement will not have anything to do in case of the false condition.
The condition is given in parentheses and must be evaluated as true (nonzero value) or false
(zero value).
If a compound statement need to be provided, it must be enclosed in opening and closing
braces.
Syntax: Simple if statement
if (condition)
{
statement-block;
}
Flow Chart: Example:
Example:
main()
{
int a=10,b=20;
if(a>b)
{
printf(“%d”,a);
}
printf(“%d”,b);
}
Output:
10
20
Whenever the specified condition becomes true, statement-block gets executed. If condition
becomes false it has nothing to do.
Whenever expression value is true (non – zero), statement1 will be executed. If the expression
value is false (zero), statement2 will be executed.
Compound statement:
One and only one statement is allowed in each part of if and else, use statement block
(compound statement) if more than one statement need to be specified.
Example: program for finding the biggest number in two.
#include<stdio.h>
int main(void)
{
int a,b;
clrscr();
printf(“Enter the two Numbers:”);
scanf(“%d %d”, &a,&b);
if(a>b)
printf(“%d is big”, a);
else
printf(“%d is big”, b);
getch();
return 0;
}
Output:
Enter the two Numbers:
10 20
20 is big
Using Nested if – else, two expressions are included. With two expressions it is possible to include three
statements that is three different paths for execution.
Example: Program to find the biggest number in three numbers.
#include<stdio.h>
int main(void)
{
int a,b,c;
clrscr();
printf("Enter a,b,c values:");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("%d is big",a);
else
printf("%d is big",c);
}
else
{
if(b>c)
printf("%d is big",b);
else
printf("%d is big",c);
}
getch();
return 0;
}
Output:
Enter a,b,c values:2 7 29
29 is big
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
The Dangling else Problem:
The nested if – else statement has to be used with extra care, otherwise it may lead to dangling else
problem.
This problem arises when there is no matching else for every if in the statement.
In C, always an else part is paired with the most recent unpaired if.
Doing so may result that some of the if statements may left unpaired.
Syntax: Flowchart:
Consider the above example syntax, from the syntax it is clear that the programmer intended the else
statement to be paired with the first if, but the compiler pair it with the second if. This is known as
dangling else problem.
The solution to the dangling else problem can be obtained by simply taking a compound statement (a set
of curly braces to separate the true part for the first if statement) into consideration.
Syntax: Flowchart:
Consider the above figure; from this it is clear that when compound statement (curly braces) is used the
true part for the first if statement is separated, now the else will be paired with the first if and the
second if remains unpaired.
The conditions are evaluated from the top to down. As soon as a true condition is found the
statement associated with it is executed and the control is transferred to the statementx by skipping
the rest of the ladder. When all n conditions become false, final else containing default statement
that will be executed
Example:
#include<stdio.h>
int main(void)
{
float m1,m2,m3,m4;
float avg;
system("cls"); //clrscr();
printf("Enter marks for (m1,m2,m3,m4):\n");
scanf("%f %f %f %f",&m1,&m2,&m3,&m4);
avg=(m1+m2+m3+m4)/4;
if(avg>=75)
printf("\nDistinction");
else if(avg<75 && avg>=60)
printf("\nFirst Class");
else if(avg<60 && avg>=50)
printf("\nSecond Class");
else if(avg<50 && avg>=40)
printf("\nThird Class");
else
printf("\nFail");
Switch Statement:
The switch statement is a way to implement a multiway selection statement in C.
The switch statement is used only when the selection condition reduces to an integral expression.
If the selection condition is not an integral value, the else – if ladder is used.
Switch is selection statement in which decision for selection is made between many alternatives.
A switch statement allows a single variable to be compared with several possible case labels, which
are represented by constant values.
If the variable matches with one of the constants, then an execution jump is made to that point.
A case label cannot appear more than once.
When none of the case labels are matching with the conditional expression then a default case will be
evaluated.
Syntax: Flowchart:
To break every case, so as to avoid multiple case execution when matching case is found,
the break statement is used. Practically speaking every case should have a break
statement as the last statement to avoid the execution of multiple statements.
Break causes the program to jump out of the switch statement, that is go to the
closing braces (}) and continues the remaining code of the program.
Example:
#include<stdio.h>
int main(void)
{
char ch;
system("cls"); //clrscr();
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
printf("Enter your choice(R,B,G):\n");
scanf("%c",&ch);
switch(ch)
{
case 'R':printf("RED");
break;
case 'B':printf("BLUE");
break;
case 'G':printf("GREEN");
break;
default: printf("Invalid Option...!");
}
getch();
return 0;
}
Output:
Enter your choice(R,B,G):
B
BLUE
LOOPS IN C (REPETITION)
Loops are nothing but an approach to repeat set of statements for a specific number of times.
Every repetition is known as an iteration in the programming terminology.
The real power of computers is in their ability to repeat an operation or a series of operations many times.
This repetition, called looping, is one of the basic structured programming concepts.
Each loop must have an expression that determines the termination point for the loop. If there is no
termination point specified the loop will iterate for infinite number of times.
The basic loop concept is shown in the following figure, as there is no termination condition specified the
loop will iterate infinitely.
while loop:
The while loop is a pretest loop.
It uses an expression (termination condition) to control the loop.
As it is a pretest loop it tests the expression before every iteration of the loop.
Syntax: Flowchart:
do – while loop:
The do – while loop is a post-test loop.
Like while loop, do – while also uses an expression to control the loop.
It tests the condition after the execution of the body.
The body of the loop must contain one and only one statement at any time. To specify more than one
statement group them using a compound statement.
Unlike other looping statement a semicolon is required at the end of the do – while statement, and
also to the statements within the body.
Example: To print 1 to 10 natural numbers
#include<stdio.h>
int main()
{
int i;
system("cls"); //clrscr();
i=1;
do
{
printf("%d ",i);
i++;
}while(i<=10);
getch();
return 0;
}
Output:
1 2 3 4 5 6 7 8 9 10
In while loop if the condition becomes false in the first iteration, the body of the loop never gets executed.
But in do – while the body of the loop gets executed at least once, even if the condition fails in the first
iteration.
for loop:
Note that the semicolon is not required at the end of the for loop statement, but the statement
within the loop body do require semicolons at the end.
The following figure compares the while loop and for loop
Option 2:
int k = 1;
for (; k< = 10; k++);
{
printf(“%d”, k);
}
Here the initialization is done in the declaration statement itself, but still the semicolon
before the condition is necessary.
If we have to read, process and print 10 integers, then we need 10 integers in memory for the duration of
the program.
We can declare and define 10 variables with a different name.
To read these 10 variables from the keyboard we need 10 read statements, and also to print these 10 variables
onto the output screen we need 10 output (printf) statements. This is something redundancy in programming
code.
The approach may look simpler and acceptable to some extend for 10 variables, but if the variable count
increases rapidly, nowhere the above concept is acceptable.
To process large amount of data, C uses a powerful data structure called array.
An array is a collection of elements of the same data type.
Array elements can be initialized, accessed and manipulated using the indexing.
Example: score[10] Here score will contain 10-elements
Array index always start at ‘0’ and end at total-number of elements minus one.
In our example the index for score will start at 0 and end at 9.
Using Arrays in C
C provides two different types of arrays
One-Dimensional arrays: In One-dimensional arrays the data are organized linearly in only one direction.
Two-Dimensional arrays: In Two-Dimensional arrays the data are organized in rows and columns, like a
matrix.
ONE-DIMENSIONAL ARRAYS:
Array declaration and definition
Like every other object in C, an array must be declared, defined and initialized before it can be used in the
program.
Array declaration tells the compiler the name of the array.
Array definition specifies the size or number of elements in the array. In a fixed length array, the size of
the array is a constant and must have a value at the compile time.
Example: type arrayname[array_size];
The declaration and definition format for a variable length is same as like a fixed length array except the
size is a variable. The array size will be determined when the program is executed. Once the size is
determined it cannot be changed.
Initialization:
Array elements in a fixed-length array can be initialized when they are declared. For variable-length
arrays they cannot be initialized when they are defined.
To initialize the array elements with a set of values, they must be enclosed in braces and separated by
commas.
It is a compile error to specify more values than elements in the array.
The initialization can be done in the following ways:
(a) Basic initialization: int scores[5]={3,7,12,24,45};
(b) Initialization without size: int scores[]={3,7,12,24,45};
(c) Partial initialization: int scores[5]={3,7,0,0,0};
(d) Initialization to all zeros: int scores[5]={0};
The first example array the score array will have 5-elements and they contain specific set of values.
In the second example, when the array is completely initializing then the size attribute can be omitted.
In the third example, if the array is initialized with partial values rest of the elements will be
initialized to zero.
In the fourth example can be used to initialize all the elements to zeros.
Inputting values:
An array can be initialized from the keyboard. The values can be read from the keyboard and initialized to
array.
The most appropriate loop to use with arrays is the for loop.
for(i=0;i<9;i++)
scanf(“%d”,&scores[i]);
Assigning values:
Array elements can be assigned individually by using a set of values, with the help of assignment operator.
Example: scores[4]=10;
Assigning one array to another array is not possible even if they match fully in type and size. To do so we
have to copy all the elements individually from one array to another.
for(i=0;i<10;i++)
scores[i]=temp[i];
Printing values:
To print the contents of the array, a normal for loop can be used.
Example: for(i=0;i<10;i++)
printf(“%d “,scores[i]);
TWO-DIMENSIONAL ARRAYS
In One-dimensional arrays the data are organized linearly in only one direction.
Many applications require data to be stored in more than one dimension.
Matrices require an array that consists of rows and columns as shown in the following figure, which is
generally called as two-dimensional array.
In C-language a two dimensional array will be considered as an array of arrays. That is a two dimensional
array is an array of one-dimensional arrays.
Initialization:
The definition of a Two-Dimensional array only reserves the memory for the elements in the array.
No values will be stored in the locations. The locations will generally contain unpredictable values or
garbage values without initialization.
Initialization of array can be done when the array is defined.
The values for the array must be enclosed in braces.
Example: int scores[3][2]={2,3,5,4,6,9};
Nested braces must be used to show the exact number of rows and columns.
Example: int scores[3][2]={{2,3,5},{4,6,9}};
In a Two-Dimensional array, if the array is completely initialized with values, only the first dimension can
be omitted. The second dimension must need to be specified.
Example: int scores[][2]={{2,3,5},{4,6,9}};
The whole array can be initialized to zeros.
Example: int scores[5][4]={0};
Inputting Values:
Another way to initialize the values is, we can read them from the keyboard.
In Two-Dimensional array, it usually requires nested for loops.
The first loop, the outer loop controls the rows from zero to the maximum number and the inner loop
controls the columns from zero to the maximum number.
Example: for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf(“%d”,&scores[i][j]);
Outputting values:
The values inside a Two-Dimensional array can be printed using two nested loops.
The first loop, the outer loop controls the rows from zero to the maximum number and the inner loop
controls the columns from zero to the maximum number.
To print the matrix in a table format, a newline is printed at the end of each row.
Example: for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
printf(“ %d”,scores[i][j]);
printf(“\n”);
}
Accessing values:
Individual elements can be initialized using the assignment operator.
scores[2][0]=23;
scores[2][2]=scores[1][1]+12;
#include <stdio.h>
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
int main(void)
{
int a[2][2], b[2][2], c[2][2], i, j;
system("cls"); //clrscr();
printf("\nEnter values for matrix A(2X2):\n");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d", &a[i][j]);
Variable-Length strings:
A much preferred solution is to create a structure that can expand and contract according to the size of the
value we want to store.
Example: To store a person name with only three characters the structure should contract and provide
three characters and to store a person name with 30-characters the structure should expand and provide
30-characers.
Here also there is a problem: as we are using a variable length structure in computers memory, there must
be a way to indicate the end of the string.
Two common techniques are used to indicate the end of the string.
o Length-Controlled Strings
o Delimited Strings
Length-Controlled Strings:
In this type of strings a count is used as the first character in the string that specifies the number of
characters in the string.
This count then be used by string manipulation functions to determine the length of the string.
Delimited Strings:
In this type of strings the end is specified by a special character known as delimiter, hence the name
delimited strings.
This concept is similar to using a full stop (.) at the end of a sentence in English. Where each sentence is
of variable length and a special symbol full stop is used to indicate the end of the sentence.
The disadvantage of using a delimiter is that it eliminates one character from being used for data in the
string.
The most common delimiter is a null character (\0).
All C strings are of variable length and delimited once.
As a string is stored in an array, the name of the string is a pointer to the beginning of the string.
There is a big difference between how a character is stored in memory and a one-character string is stored.
The character requires only one memory location, but the one-character string requires two memory
locations one for actual character and one for delimiter.
To store an empty string in memory also requires one memory location to store the delimiter.
String Constants:
A string literal or a string constant is a sequence of characters enclosed in double quotes.
When string constants are used in a program, C automatically creates an array of characters, initializes to a
null delimited string, and stores it.
Example: “C is a programming language”
“Hello World”
A string literal is stored in memory like any other object. It has an address, and can be referred by using a
pointer. Here the string literal as it is a sequence of characters, itself a pointer constant to the first element.
The string itself can be used to refer the individual characters by using index.
Example: “hello”[1] e
#include<stdio.h>
int main(void)
{
char name[30];
printf("Enter name: ");
gets(name); //Function to read string from user.
printf("Name: ");
puts(name); //Function to display string.
return 0;
}
C provides different predefined set of string functions which are helpful in manipulating the strings.
String Length
strlen () function:
This function counts and returns the number of characters in a string. It takes the form
Syntax: int n=strlen(str);
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
int len;
char str[]="hello";
len=strlen(str);
printf("%d",len);
getch();
return 0;
}
Output:
5
String Copy
The String copy functions strcpy(); copies the contents from one string including the null character to
another string.
There are two string copy functions:
I. Basic string copy strcpy();
II. String copy length controlled strncpy();
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
char fromstr[]="hello",tostr[10];
strcpy(tostr,fromstr);
puts(tostr);
puts(fromstr);
getch();
return 0;
}
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
char fromstr[]="hello",tostr[10];
strncpy(tostr,fromstr,2);
puts(tostr);
puts(fromstr);
getch();
return 0;
}
Output:
he
hello
Sring Compare
C has two string compare functions:
I. Basic string compare strcmp();
II. String compare length controlled strncmp();
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[ ] = "Hyderabad" ;
char str2[ ] = "Hydarabad" ;
int i, j, k;
i = strncmp ( str1, str2, 3) ;
j = strncmp ( str1, str2, 4) ;
k = strncmp ( str1, str2, 10) ;
printf ( "\n%d %d %d", i, j, k ) ;
}
Output
0 4 4
String Concatenation
The string concatenation function appends one string to the end of another string.
The size of the destination string should be large enough to hold the resulting string. If it is not the data at
the end of the destination string will be destroyed.
C has two string concatenation functions:
I. Basic string concatenation strcat();
II. String concatenation length controlled strncat();
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[ ] = "Hyderabad" ;
char str2[ ] = "ISL" ;
strcat ( str1, str2);
printf ( "%s", str1);
getch();
return 0;
}
MD AFZAL Mob: 8179700193
Asst. Professor mdafzal.mbnr@gmail.com
Output
HyderabadISL
Example:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[ ] = "Hyderabad" ;
char str2[ ] = "ISL" ;
strncat ( str1, str2, 2) ;
printf ( "%s", str1 ) ;
getch();
return 0;
}
Output
HyderabadIS
String reverse
strrev() function:
The function strrev is used to reverse the contents of the given string.
The function strrev(); takes the string and reverses it, and places the reversed string in the given string
only.
Syntax: strrev(string);
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
toupper() function takes the character value as parameter, and converts it into the uppercase character.
If the converted character is already in upper case, it remains as it is.
Syntax: tolower(char);
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
char ch = 'i';
printf("%c",toupper(ch));
getch();
return 0;
}
Output:
I
tolower() function:
tolower() function takes the character value as parameter, and converts it into the lowercase character.
If the converted character is already in lower case, it remains as it is.
Sybtax: tolower(char);
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
char ch = 'I';
printf("%c",tolower(ch));
getch();
return 0;
}
Output:
i
toascii() function takes the character value as parameter, and converts it into the equivalent ASCII value.
Syntax: toascii(char);
Example:
#include<stdio.h>
#include<string.h>
int main(void)
{
char ch = 'A';
printf("%d",toascii(ch));
getch();
return 0;
}
Output:
65