0% found this document useful (0 votes)
0 views

Week 2_Final

The document covers the fundamentals of variables and data types in C programming, explaining how variables act as containers for data and the importance of data types in defining how data is stored and manipulated. It discusses various data types including integers, characters, and floating-point numbers, along with their modifiers and memory allocation. Additionally, it outlines the rules for naming variables, declaring them, and the differences between local and global variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Week 2_Final

The document covers the fundamentals of variables and data types in C programming, explaining how variables act as containers for data and the importance of data types in defining how data is stored and manipulated. It discusses various data types including integers, characters, and floating-point numbers, along with their modifiers and memory allocation. Additionally, it outlines the rules for naming variables, declaring them, and the differences between local and global variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Week 2

Topic: Variables in C programming

S. No. Topics to be covered


1. Variables and Data types
2. Character, Numerical and other data types

A variable is a container (storage area) to hold data. In the C programming


language, a variable is a designated memory space within the program that
stores data of various types. Different categories of variables exist in C, which
are determined by factors such as scope, storage class, lifetime, and the nature
of the data they hold. A variable is a fundamental component of a C program
that can be directly utilised in expressions as a replacement for the value it
represents.
Within a program, variables and constants serve as fundamental data items that
are changed.

Let us see some basic terminologies:


Declarations define the variables to be used, specifying their data type and
possibly their initial values.
Operators determine the precise actions to be performed on them.
Expressions are mathematical constructs that combine variables and constants
to produce new values. The classification of an item determines the spectrum of
potential values it may hold and the operations that can be performed on it.
In this session, you will learn how to represent the integer data , the various
modifiers used, along with how to represent integers in the memory. You will
also learn about the usage of variables, and their naming rules and how to define
and declare these variables
 ​
These are two images and how are they created?
Images are made up of pixels an abbreviated name for picture element, these
pixels are arranged in a grid of columns and rows. Each pixel is represented by
a binary number, with 0 representing black and 1 representing white. The
quality of an image is determined by the number of pixels it uses.
Every data here is in Bits and bytes. Bits are used to represent different types of
data. Your program needs to be able to retain a record of the type of data that is
stored in each location within the memory of the computer.
Looking at the bigger picture here is what bit, byte and word mean .
• All data is represented as a sequence of bits, where each bit can assume a
value of either 0 or 1. A byte consists of 8 bits.
• Word is a term denoting largest data size handled by processor, which is
usually 32 bits on older computers and 64 bits on new computers.
How much space a data type will occupy depends upon the size of the machine
being used. Data types in C are important because they define how data is used
in a program, including how it is stored, represented, and operated on. Each data
type is represented by a specific keyword. Each variable has a unique type that
decides what values it can hold, how data is stored in memory, and what actions
can be performed on it. The system helps the computer find type-mismatch
errors to avoid many problems. This is done by making the coder clearly specify
a type for every variable and interface in the program.
There are three basic types in the C language: characters, and integer and
floating-point numbers.
Before separating data into the data types let us understand the concept of
variables. In C, a variable is a container that can hold values. The memory is
stored within them according to the type of variable. For eg. int ans = 100;
The type of data that a variable can store is the data_type. A variable_name is
the user given name and value signifies the value assigned to the variable by the
user.
s​
• char mott;
• int x;
• long ans;
• float random;
• double pi;
These are a few examples of variable type and their identifiers. Like a character
data type is declared as char mott, int data type x and so on.
The declaration of a variable in C provides the compiler with information
regarding the existence of the variable, including its name and the data type that
it uses. During the process of initialising the variable, memory will be allocated,
and an entry will be made in the symbol table. This happens when the variable
is defined.
A variable is nothing but whose quantity may vary during the program
execution. The names that are given to the computer memory location are the
variable names where we store different values such as integer, cha, float etc.
data stored in a location with a particular type of variable name can hold only
that type of data, for example, an integer variable cannot hold float values and
integer variable can store only integer values. The general syntax of variable
declaration is type that is the type of variable followed by the variable list,
where we can have more than one variable in a single statement.
Talking about the Rules of Naming Variables and Assigning Values. Example –
Sum, _sum
In the first example sum begins with a letter S, which is a capital letter. We can
also use a smaller case letter or a lower case letter while naming. The second
example of variable name begins with an underscore, which is also allowed
variable name. It is the only special symbol which is allowed. The next rule says
that variables are case sensitive, which means the lower case letters and the
upper case letters that are used in variables are considered as completely
different. Example – add, ADD, AdD. In the example here, the first example
add we have used all the lower case letters for the variable name. In the second
example, we have used all upper case letters for variable name. In the third
example, we have used the combination of upper case letters and the lower case
letters. The compiler considers all these three examples as three complete
different variable names.
Variable names can also be constructed with digits and letters. Example –
Sum_1. We can have a variable name with the combination of these but a point
to remember is that variable names have to start with an alphabet or an
underscore and then digits can follow. Also we cannot use any of the special
symbols other than underscore while constructing a variable name. for example
Sum_1is correct but Sum.1 is not a valid variable name. While naming the
variables, we cannot be using keywords as variable names. For example, we
cannot use main as a variable name or define as a variable name because they
are the keywords of C programming language. variable names can be of any
length. But it is preferred to have up to eight characters as the variable length.
Now that we know how to construct variable names; by following different
rules, we also have to know how to declare these variables. Every variable in C
program must be declared. The syntax for declaring a variable name is, data
type followed by variable name. You can have a single variable, or you can have
a variable list in the example here is int x, y, z; now X, Y, Z here are different
variables of type integer all x, y, z variables will hold only integer values. We
can divide this statement into int x, int y and int z. But C programming allows
you to put all the similar type of variables under one single statement and all the
variables must be separated by a comma. In the second example, char flat, ch
are the variables of type character. While declaring the variables, no memory
will be allocated for a variable. It will happen only after we define the variable.
For example, when we say int x; then a memory will not be allocated to the
variable x. But when you say int x = 100; then the memory will be allocated to
the variable x.
After declaring the variable, we also must assign the values to the variable. This
value can be any constant value, meaning it can have a real value. an integer
value or a character value. Depending on the type of the variable, the variable
will hold that particular value. initialization of variable means assigning a value
to the variable. We also have to assign the value to the variable. assigning the
value of variable is done by writing following syntax, say data type, followed
by its variable name equal to symbol and data value. this is how we do the
assignment and the value that we have to allocate is assigned to the variable.
For example, int x = 50 means we are assigning value 50 to the variable x of
type integer. We can also do multiple assignments in a single statement. Here in
this example, x and y both should be of same type. Now, in this statement, we
are declaring and assigning the values to the variables in a single statement.
When we say int x = 50, y= 30 we are assigning 50 to variable x, and assigning
30 to variable y and x and y both are of integer type. Or int z=a=10 can also be
written where 10 is assigned to both z and a. In the next example, we are
assigning value X to flag, which is of type char. And also we're assigning a
value capital I to ch, which is a variable name of type char.
Now where can we declare these variables? Can the variables be declared
throughout the program? The variables can be declared as a Local variables, as
formal parameters or, as global variables. Variables are called as local variables
when they are declared inside the function. For example, inside main function if
I am declaring two variables, say int A and B then these variables are of type
integer and they're called as local variables for the main function, and the scope
of these variables only will only be within the main function. We can also use
variables, or we can also declare variables as formal parameters while defining
a function. We can declare variables outside the functions wherein these
variables are called as global variables and scope of these global variables will
be throughout the program.
After variable declaration and assignment let us understand data types in C
programming language. The first among them is int or integer data type. The
word size of a computer machine allows us to further understand what the range
of values are that a specific data can occupy within the computer's memory.
Integers can be defined as whole numbers with certain range of values. These
integers can further be classified as signed numbers and unsigned numbers. In
C, signed and unsigned numbers refer to the ability of a data type to represent
both positive and negative values through signed integers or only positive
values in unsigned integers. Unsigned means the numbers which do not have
any specific sign, particularly whole numbers.
Data representation in computer is dependent on the size of the machine. How
much memory can be occupied by an integer type is always dependent on the
machines configuration. An integer type can occupy from two bytes to four
bytes to even eight bytes of memory. This always depends on the processor,
which allocates the memory. A 16 bit processor will usually allocate two bytes
of memory for an integer value. A 32 bit processor will allocate four bytes of
memory to an integer value and 64 bit processor will allocate eight bytes of
memory for a integer value. This word size allows us to further understand what
a range of values a specific data can occupy within the computer's memory. One
such data being integers which can store whole numbers with certain range of
values.
Integers can further be classified as signed and unsigned numbers. Signed
Numbers can be positive numbers or negative numbers. Unsigned meanings
which the numbers which do not have any specific sign, particularly whole
numbers As it’s known that integers will store certain range of values, C
language allows us to alter this range by adding certain type modifiers. The type
modifiers alters the meaning of the base type more precisely to our need. The
modifiers that we can see here are short and long, which are usually preceded
.​​
before the data type that we use. Short int will have the lesser range of values
than integer and long int can contain higher range of values than int

Table 1: Basic Types, Qualifiers and Size


Table 1 represents the kind of modifiers that are used along with the integer
type. In the table, the first column represents the integer type, along with the
modifiers like int or signed, or signed int, or unsigned int, short or signed short
int, or unsigned short int, long int or signed long int and unsigned long int. The
second column represents the number of bits that are occupied in the memory.
Third column represents the range of values. The word size depends on the
machine. Usually, the integer data type occupies two bytes of data in the
computer's memory. Two bytes, means one byte has eight bits. Two bytes has 16
bits of data. Bytes is a binary digit. Binary value can either be zero or one.
Every information in the computer's memory is stored in the form of binary
value, whether it is an alphabet or a character, or it can be anything. Unsigned
int has a size of 16 bits that is it occupies 16 bits of memory, which ranges from
0 to 65,535. The range of values is from two to the power of 0 to 2 to the power
of 16 minus one. It can be zero to 65,535 range of values for an unsigned int for
assignment. For a signed int, it will have the range of values for negative
numbers as well as positive numbers. So, half of 65,535 will be negative range
of values and half of 65,535 will be a range of positive values. The range of
negative values for assignment will be minus 32,768 to 0, and positive values
will be 0 to 32,767. The same holds true for short int, which occupies 8 bits.
.​
Since it occupies lesser range of values than integer so it can store values from 0
to 255 or -128 to 127 in case of signed short int.
A doubt that may arise while using these integer values and fractional values is,
that can we assign fractional values to integer type, or can we store fractional
values into integer type? Is integer data type the correct format to store
fractional values? The answer to this is that though we might assign a fractional
value to integer type, it will not be stored in memory as fractional value, rather
the decimal part of data will be truncated. That is, all the values after the
decimal point will be truncated and will again be stored as an integer value. We
can always store an integer value by using float data type, fractional values
cannot be stored using an integer data type
Topic 2
In this session we will be talking about Data types. Data types can be broadly
classified into primary data type and secondary data type. Primary data type is a
primitive data type which cannot be manipulated where secondary data types
are user defined data types, which can be manipulated as per the user
requirements. This means that secondary or user defined data types can be used
as per the needs of program. Primitive data types are primary data types. Data
types such as character, integer, float, double VOID, cannot be manipulated by
the user or the programmer, their basic functionalities remain the same. Having
said that, user also can have his own data types, which are a pointer structure
union and enumerated data types, which he can make use of in the program that
he is implementing. Different data types will hold different kinds of value. Like
we can see here int holds integer values, char is used to hold character values,
and float holds the fractional values.
Every data type will be having a certain range of values to hold and depending
upon the word size of the machine the values are being occupied. A 2-byte
integer can represent values from -32,768 to 32,767 or 0 to 65,535. Two bytes is
equivalent to 16 bits, which means that 2 bytes can represent 65,536 different
.​
combinations. Because 2 raise to the power 16 is 65536. The range of all the
data types can be altered by modifiers such as short and long. Like using a short
modifier for an integer reduces the range of values a short int can store and
using a long int increases the range of values.
Float data type is used to store floating-point values that is to store decimal and
exponential values. It is used to store decimal numbers with single precision. In
this example we have declared a variable X of type float. X1 is of type double
and X2 is of type long double. The range is from 1.2E-38 to 3.4E+38, the size it
occupies is 4 bytes and the format specifier for a float value is %f. A float data
type occupies 4 bytes of space in the memory and in case we have to store
values with high precision then we use double or long double along with the
float data type. Double occupies the space of 8 bytes in the memory and long
double will extend to 10 bytes of memory space.
In the primitive data types the next data type is the char or character datatype. If
a single character is stored in a char data variable then it occupies one byte of
memory. If a group of characters is being stored for that we must use a character
array. Array is a concept which is discussed in the upcoming sessions. If hello
has to be stored then a character array of size 6 will be declared because 5 bytes
will be for each character of the word hello and one space for the null character
which marks the termination of the string. Likewise if another character array
greet is declared and it is initialised with the string “hello world” then the total
space that it will be occupying will be 12 bytes. Because here one byte is of
space and another for the null character.
Operators
In C programming language, an operator is a symbol that enables us to carry out
particular computations on values and variables. These computations might be
mathematical, relational, bitwise, conditional, or logical in nature. "Operands"
are the values and variables that are utilised in conjunction with operators. From
this perspective, we can say that the symbols that carry out operations on
operands are known as operators. Like the + operator is often used to add
together two values, it can also be used to add together a variable and a value, or
a variable and another variable. Suppose a programmer has to perform addition
on 2 variables and the variables are A & B on which the addition has to be
performed. Here an addition operator would be used that is a + sign which tells
the compiler to perform addition operation. So, operator is a symbol which tells
the compiler to perform certain kind of manipulations and these symbols are
known as operators.
Expression
Expression is a combination of variables operators and operands. For example
c=a+b, here c, a & b are operands, and + and = (equals to) sign are operators.
Therefore, an expression is a statement which is reduced to a single value that
means the result of a+b is stored in a single variable C.

'C' operators can be classified into 8 categories.


• Arithmetic operators.
• Relational operators.
• Logical operators.
• Conditional operators.
• Assignment operators.
• Increment and decrement operators.
• Bitwise operators.
• Special operators that is a comma operator.
The arithmetic operators are used to perform mathematical operations, the
relational operators are used to do a comparison between 2 values, the logical
operators are used as logic gates to check whether the expression value is true or
false, an assignment operator is used to assign a value to a variable.
To do an increment or decrement in a value we make use of the increment and
decrement operator they are used to increase or decrease the value by one
respectively. Conditional operators are used to check the given condition is true
or not . To manipulate the data at the bit level bitwise operators are being used.
And there is also a special operator known as the comma operator.
Arithmetic Operators in C
C language provides various arithmetic operators. the arithmetic operations that
we have are addition, subtraction, multiplication, division and also modulo
operator. Now here, plus is the operator that is used for performing addition. Let
us assume we have two variables X and Y so X+ Y would give the sum of the
expression. We can also have more than two variables. For example, we can
have X, Y, Z, and the expression would be X + Y +Z.
Next, we have is the minus operator or minus symbol to perform subtraction.
Then we have asterisk symbol, that looks like star. We have asterisk symbol to
perform multiplication. We do not use the normal multiplication symbol which
looks like x. Then forward slash is used for performing division. Then we have
modulus operator to get remainder of two values. All these operators can be
used with more than two variables.
There are certain things which have to be noted before the use of division
operator or modulo operator. When we are dividing 2 integer values and it's
remainder leads to a fractional value, then division operator truncates the
remainder's values after the decimal point. and also modulus operator cannot be
applied on float are double values. it can be applied on integer values only.
Precedence of arithmetic operators
Which operation has to be performed first, and which operation has to be
performed next is known as the precedence of operators. If there are more than
one operator in an expression, which operation needs to be performed first is
specified by precedence. Another thing to be noted is Associativity: If more than
one operator has the same precedence which operation we need to perform is
specified by associativity. Multiplication division operator and modulus
operator have higher precedence than addition operator and subtraction
operator.

This is a sample program which depicts the use of each operators and how are
they being used
If we consider an expression, a * b / c + d then ‘*’ and ‘/’ has the same
precedence, but multiplication is performed first and then division will be
performed because the associativity is from left to a right after performing
multiplication and then division. And addition will be performed onto the whole
result of a * b / c.
Let us consider a small program to demonstrate how to use division operator
and modulus operator.
#include main()
{
int months , days ;
printf ( "Enter days \n “ ) ;
scanf ( "%d“ , &days ) ;
months = days / 30 ;
days = days % 30 ;
printf ( "Months =%d Days= %d \n " , months, days);
}
The first line is a declaration statement where we are declaring two variables’
months and days of type integer, so months and days will store integer values in
them. The second printf statement which displays the statement, enter days onto
the output console where users can enter a value. The value that is entered by
the user will be read through the scanf statement where the value that user
enters will be stored in the variable days. In the next statement, we are dividing
the value of the variable days by 30 by using a division operator. Now this
expression will give the quotient and that quotient will be assigned to the
variable months. In the next statement we are using a modules operator. days
value will be divided by 30 and remainder value will be assigned to days
variable again. The last statement simply displays the value of months and days.
Relational operators:
These operators are used to compare quantities and ascertain the relationship
between them. The outcome of the relational expression is either one or zero. It
is one if the specified relation holds true and zero if the relation is false. These
operators are termed binary operators as they require two expressions as
operands.

Operator Expression Description


< A<B A is less than B
<= A<=B A is less than or equal to B
> A>B A is greater than B
>= A>=B A is greater than or equal to B
== A==B A is equal to B
Table 2: Relational Operators in C
Table 2 shows all the relational operators that can be used for comparison in C
programming language. If we have to compare if X is less than y then less than
operator symbol is used. If we have to compare if two values are less than or
equal to each other so that we use less than equal to operator. then if we have to
compare if values are greater than each other. If X is greater than y than greater
than symbol is used. If we have to compare if X is greater than or equal to y
than greater than and equal to operator is used. If we have to compare if both
values are equal, that is, if X is equal to y then, we use equal to operators.
Remember, if we're using one equal to operator, then it is an assignment
operator. If we say X is equal to 10, the value 10 will be assigned to X but if we
say X double equal to Y then, the value of X is compared with the value of Y
and true value is returned if both the values are equal. In the same way if we
have to check if one value is not equal to the other value, that is, X is not equal
to Y. Then we use exclamation symbol along with equal to symbol. These are
the relational operators that we have in C language.
Any relational expression will result in either a true value or a false value. That
means value one for true value and zero for a false value. For example, in the
expression, seven is compared with eight. If 7 is less than 8 it's a true value, so
it results in one. The next expression, -34 plus 8 is greater than 23 - 5. Since the
expression evaluates to -26 > 18. Which is false so it give 0. If in the third
expression where a = 3, b = 2, c = 1; then what should be the value of a > b >
c?
We have to take in consideration the concept of associativity here. The
associativity of relational operators is left -> right. Here 3 is a’s value, 2 is b’s
value so we check if 3>2. It’s a true value. Means a value 1. Now c’s value is 1
so, one greater than one will yield zero because it is false. One is not greater
than one, but one is equal to one. And when you have multiple relational
operators in the relational expression, then the associativity of it is from left to
right.
In associativity we have to know the precedence of these relational operators, as
well. which operator has higher precedence than which operators and which
operators have same precedence. The operators which have higher precedence
over equality operators are:
greater than
greater than equal to
less than
less than or equal to.
If we have equal to operator (==) and not equal to (!=) operator, these operators
have lower precedence than greater than greater than or equal to less than our
less than or equal to operators.
Slide 24
Let us consider an expression: “3>=2==-4<0” we have all relational operators
here. The associativity is considered from left to right. That means whichever
symbol comes first and is in higher, precedence will be resolved. if we compare
we have a three operators here. One is greater than or equal to operator. Then
we have equal to operator. Then we have less than operator. Greater than or
equal to operator and less than operator has the same precedence, whereas equal
to operator has lower precedence. Following the associativity, from left to right,
though greater than or equal to symbol and less than symbol has the same
precedence greater than or equal to operation is performed first and then the
less than operator operation is performed. And then the values are compared
with the equal to operator. We check if 3 is greater than or equal to 2, it is true.
This expression is a true value. Then we move to the less than operator. We
compare -4 is less than 0, -4<0 also gives value true. this 3>= 2 will yield one,
-4<0 will also yield 1. Now we compare one with one by using equal to symbol.
1==1 hold together is a true value.
Logical Operators
Logical operators are usually used are to yield a true value or of false value. Of
two different expressions or two variables. The three logical operators that C
language uses are logical and, logical or and logical Not. logical operator is
composed of double symbols. We should not be using a single ampersand or a
single pipe symbol. And we also have a unary operator which performs logical
not operation, which is denoted by a simple exclamation mark. The associativity
in the expression is from left to right, so depending on which logical operator
comes first we evaluate that particular expression and also the evaluation stops
once we get to know the result, whether it is a true value or a false value.

Operator Details

AND (&&) If both A and B are non-zero, then the condition becomes
TRUE
A=1 && B=1 1
A=1 && B=0 0
OR (||) If any of the A or B is non-zero, then the condition
becomes TRUE
A=0 || B=1 1
A=0 || B=0 0
NOT (!) It reverses logical state of the operand. If a condition is
TRUE, then NOT operator will make it FALSE

Table 3 : Logical Operators


Table 3 gives us the logical operators and their details. When logical AND
operator is used with two variables A and B, then if both are non-zero values,
then the result will be true. Otherwise, even if one of the variables is zero, then
the value will be false. Then A logical OR B which will return false when both
the values are non-zero. Otherwise, it will return a true value.
The precedence of && is higher than that of ||, and both are lower than
relational operators.
To assign a certain value to a variable or to expression an assignment operator is
used. For example X operator=expression, Assignment operator is usually
denoted by ‘=‘. X is a variable here, and operator op along with which is
combined with equal to symbol. Then we have an expression. This is a
shorthand assignment. So instead of writing X = X+ 10, we can just write or
express it as X+=10. Both the expressions yield same results. It is also known as
a compound assignment operator, is a way to combine an arithmetic or bitwise
operator with an assignment operator. This makes it possible to perform an
operation and assignment in a single step, which can make code more concise
and readable.
Conditional Operator
The conditional operator in C is analogous to the if-else statement, as it adheres
to the same algorithm. However, the conditional operator occupies far less
memory and facilitates the concise expression of if-else statements. It is
alternatively referred to as the ternary operator in the C programming language
due to its operation on three operands. For example exp1?exp2:exp3. There are
three expressions which are used here. All the three are conditional expressions.
Expression 1 and expression 2 is separated by a question mark. Expression 2
and expression 3 is separated by a colon upon the true or false value of
expression.
The conditional operator operates as follows:
The first step is to evaluate the condition denoted as Expression1.
Step 2A: Expression2 will be executed if the condition(Expression1) is True.
Step 2B: If the condition expressed by Expression1 is false, Expression3 will be
executed.
Proceed to Step 3: Results will be provided.
Library Functions
In C, a function is a set of statements that are intended to perform a prescribed
operation when called upon. These autonomous blocks of code, commonly
known as subroutines or procedures in other programming languages, have a
crucial function in organising a C program. Modules offer a means to
decompose a programme into smaller, more manageable components, therefore
enhancing the readability, reusability, and maintainability of the code. C comes
with a rich set of built-in functions that are part of the standard library. They are
also known as Library functions. Certain library functions that we use very
frequently in programs are the standard input output operations, which are printf
and scanf functions. We do various operations on characters. Those are string
functions. certain functions which carry out mathematical functions are also
there.
We have many library functions which are similar so what c language does is it
groups all the similar library function under one library file and in an object
program these library files can be included. How do we access these library
function? we just have to write the function name and it's associated
parameters. And where does the function return a value? It returns a value to a
constant or an identifier.
Suppose we need to find a square root of a value are we need to find a log
value. Then we need to make use of certain mathematical functions. Usually, the
frequently used mathematical functions are to find out, sin value, or a cos value
or to find out a square root value. these mathematical functions are already in
built in C programming and what we have to do is to include a header file called
math.h at the beginning of the program. By this we can make use of all these
inbuilt mathematical functions which are already there in the library.

−b ± b 2 − 4ac
If we consider an expression say . This is the way to write
2a
an expression manually, when we're using any mathematical function or
mathematical expression, we use division operator. we use a root symbol. But if
we right the expression in the same way in program, the compiler will not
understand because it uses certain mathematical functions. To make sure the
compiler understands the expression, we have to write it in certain way.
For example, if you say 2a it is understood, that it is 2*a. but here to make sure
the compiler understands you have to specify 2 is multiplied by a by using
multiplication operator, so the whole expression can be expressed
programmatically as = ( -b + sqrt ( b*b - 4*a*c ) ) / ( 2 * a ) .

Function Purpose
toupper(c) Convert letter to uppercase
tolower(c) Convert letter to lowercase
tan(d) Return the tangent of d
log(d) Return the natural logarithmic of d
ceil(d) Round up to next integer value
floor(d) Round down to next integer value
Table 3: Few examples of library functions
Table 3 lists some of the library functions, which we mostly use. Not all the
library functions are mentioned, but few of the library functions which can be
invoked, for example, toupper() is a function that we invoke to convert a
character or a letter in to an uppercase value. We can also use in the same way
tolower() function. to get tangent value a tan function is used, to get a
logarithmic value, we use log function. We can also get ceiling and floor values
by using ceil and floor functions.
Program to Convert a Lowercase to Uppercase
#include<stdio.h>
#include <ctype.h>
main()
{
int lower, upper;
lower = getchar();
upper = toupper(lower);
putchar(upper);
}
This is a simple program to demonstrate how to include library functions in the
program. This program is basically converting a lower case character in to
uppercase character.
Program showing the use of Library Functions
#include<stdio.h>
#include<ctype.h>
#include<math.h>
main()
{
int i = -10, e = 2, d =10;
float rad = 1.57;
double d1 = 2.0, d2 = 3.0;
printf(“%d\n”, abs(i));
printf(“%f\n”, exp(rad));
printf(“%f\n”, pow(d1,d2));
printf(“%f\n”, sin(rad));
printf(“%f\n”, cos(rad));
printf(“%d\n”, log(rad));
}
In this program the abs(i) function returns the absolute value of an integer, sin()
computes the sine of an angle given in radians here rad = 1.57 is approximately
π/2 radians, so sin(rad) will be close to 1. Similarly cos(rad) will be 0.00,
exp(rad) will be 4.811 approximately, log(rad) will be .451 approximately, and
pow(d1,d2) will give the output 8.
Bit-wise Operators
As we know the values are considered by the machine as a binary values, the
stored values will be converted to a binary number always. And then, to perform
operations at the bit level, we use a bit wise operators. We have various bit wise
operators.

Operator Description
& To perform bit-wise AND operation
| To perform bit-wise OR operation
~ To perform bit-wise NOT operation
^ To perform bit-wise XOR operation
<< To perform bit-wise left shift
>> To perform bit-wise right shift
Table 4: Bit wise operators
Comma Operator
We also have a special operator which is called as a common operator. We use
comma operator to link the related expressions together. For example, if we
have to declare two integer variables and we have to assign the values also at
the same time. To do it in a single statement we can write it as int a=10,b=20. If
suppose the statement is Value = ( X = 10, Y = 5, X + Y);
Then following the associativity rule of left to right and precedency rule the
expression will be evaluated as:
First assigns the value 10 to X,
Then assigns 5 to Y,
X + Y = 10 + 5 = 15
And finally assigns 15 to Value.

References:
1. Book Let Us C, by Yashavant Kanetkar
2. Book Programming in ANSI C, by E. Balagurusamy
3. SLM of Manipal University Jaipur
4. Use of AI tools for language and syntax corrections.

You might also like