Professional Documents
Culture Documents
UNIT NO 2
BASICS OF C PROGRAMMING
I I
20ESCS101
Problem Solving and Programming in C
(Common to ALL Departments)
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
INTEGER TYPE
● Integer data type allows a variable to store numeric values.
● “int” keyword is used to refer integer data type.
● The storage size of int data type is 2 or 4 or 8 byte.
● It varies depend upon the processor in the CPU that we use. If we are using 16 bit processor, 2 byte
(16 bit) of memory will be allocated for int data type.
● Likewise, 4 byte (32 bit) of memory for 32 bit processor and 8 byte (64 bit) of memory for 64 bit
processor is allocated for int datatype.
● int (2 byte) can store values from -32,768 to +32,767
● int (4 byte) can store values from -2,147,483,648 to +2,147,483,647.
● If you want to use the integer value that crosses the above limit, you can go for “long int” and “long
long int” for which the limits are very high.
Example
0,8,-5
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
● float or double variable type is used to store decimal values or real number values.
● floating point is denoted by float keyword in C
● The storage size of the floating point is 4 bytes but it depends upon the platform of the system.
● float data type is used to declare decimal numbers(no whole value) that can have positive and
negative value
Example
23.34, -5.34
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Example
‘A,’, ‘c’
● Void is a data type(it is also keyword) means No value or nothing. it is mostly used in function
identification for not return anything.
● You can not create a variable as void type
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Array, pointers, struct, and union are the derived data types in C.
Array:
Array in C stores multiple values of the same data type. That means we can have an
array of integers, chars, floats, doubles, etc
Pointers:
Pointers are considered by many to be complex in C, but that is not the case. Simply put,
a pointer is just a variable that stores the address of another variable. A pointer can store the
address of variables of any data types. This allows for dynamic memory allocation in C.
Pointers also help in passing variables by reference. The pointer is defined by using a
‘*’operator.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
Structure
A struct is a composite structure that can contain variables of different data types. For
example, all the student data that we declared earlier in basic data types can be put under one
structure. Instead of having the information scattered, when we give it a structure, it is easier to
store information about more students.
Union
With a union, you can store different data types in the same memory location. The union
can have many members, but only one member can have a value at one time. Union, is thus, a
special kind of data type in C.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to All Departments )
C KEYWORDS
Keywords are predefined, reserved words used in programming that have special
meanings to the compiler. Keywords are part of the syntax and they cannot be used as an
identifier.
VIDEO LINK
1. https://www.youtube.com/watch?v=bS6uNMmIoQ0
1. https://www.youtube.com/watch?v=Bd1KPBVbVlo