Unit-2-Part-A
Unit-2-Part-A
Tech-CSE)
Course Code: 19002200
Subject: Introduction to Programming with C (Unit-2)
Faculty Name:
Dr. Saba Hilal
Professor (CSE)
School of
Engineering &
Technology
Here, the type of number variable is int. You cannot assign a floating-point (decimal) value 5.5 to this
variable. Also, you cannot redefine the data type of the variable to double. By the way, to store the decimal
values in C, you need to declare its type to either double or float.
(type_name) expression
In simpler words, the implicit type casting performs the conversion without altering any of the values
stored in the program’s variables.
Follow these points to understand what rules the implicit type casting follows in a C program:
•If we are performing a conversion on two of the different data types in a program, then the conversion of
the lower data type to the higher data type will occur automatically.
•If we suppose that we are performing the type casting operation among two different data types like float
and int, then the resultant value would be the floating data type (float).
Syntax:
(name_of_data_type) expression
Here, name_of_data_type refers to the name of that data type to which we want to convert the available data
type in the code. This expression can be a constant, a variable, or even an actual expression in a program.
atof(): We use it to convert the data type string into the data type float.
atoi(): We use it to convert the data type string into the data type int.
atbol(): We use it to convert the data type string into the data type long.
itoba(): We use it to convert the data type int into the data type string.
ltoa(): We use it to convert the data type long into the data type string.
Single-line Comments
Single-line comments start with two forward
slashes (//).
Any text between // and the end of the line is
ignored by the compiler (will not be executed).
Multi-line comments
Multi-line comments start with /* and ends
with */.
Any text between /* and */ will be ignored by
the compiler.
Programme Name Semester- B.Tech-I-Sem Subject- Introduction To Programming with C
Header Files in C
In C language, header files contain a set of
predefined standard library functions.
iostream.h
iostream provides basic input and output services for C++ programs. iostream uses
the objects cin , cout , cerr , and clog for sending data to and from the standard
streams input, output, error (unbuffered), and log (buffered) respectively.
conio.h
This header file declares several useful library functions for performing "console
input and output" from a program. If you are using functions like clrscr(), getch(),
putch, cputs, etc we need to include conio.
Equal to operator: Represented as ‘==’, the equal to operator checks whether the
two given operands are equal or not. If so, it returns true. Otherwise, it returns
false. For example, 5==5 will return true.
Not equal to operator: Represented as ‘!=’, the not equal to operator checks
whether the two given operands are equal or not. If not, it returns true. Otherwise,
it returns false. It is the exact boolean complement of the ‘==’ operator. For example,
5!=5 will return false.
Logical OR operator: The ‘||’ operator returns true even if one (or both) of the
conditions under consideration is satisfied. Otherwise, it returns false. For
example, a || b returns true if one of a or b, or both are true (i.e. non-zero). Of
course, it returns true when both a and b are true.
Logical NOT operator: The ‘!’ operator returns true the condition in consideration
is not satisfied. Otherwise, it returns false. For example, !a returns true if a is false,
i.e. when a=0.
Programme Name Semester- B.Tech-I-Sem Subject- Introduction To Programming with C
Bitwise Operators in C
• The & (bitwise AND) in C or C++ takes two numbers as operands and does AND
on every bit of two numbers. The result of AND is 1 only if both bits are 1.
• The | (bitwise OR) in C or C++ takes two numbers as operands and does OR on
every bit of two numbers. The result of OR is 1 if any of the two bits is 1.
• The ^ (bitwise XOR) in C or C++ takes two numbers as operands and does XOR
on every bit of two numbers. The result of XOR is 1 if the two bits are different.
• The << (left shift) in C or C++ takes two numbers, the left shifts the bits of the
first operand, and the second operand decides the number of places to shift.
• The >> (right shift) in C or C++ takes two numbers, right shifts the bits of the
first operand, and the second operand decides the number of places to shift.
• The ~ (bitwise NOT) in C or C++ takes one number and inverts all bits of it.