Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Programming in C.pptx
1. Programming in C
Avishek Bhattacharjee
(B-TECH Student at HETC, 3+ Years of Programming Experience as of 2022)
2. What is Programming?
• Whenever we try to do some operations or give some problems, or think
some logics and steps to solve a problem is called Programming.
• Simply just do or run or think a program through sequence of steps is called
Programing. And this sequence of steps is called Algorithm.
Avishek Bhattacharjee
3. What is Programming Language?
• In Simple language like English, Bengali or Hindi, there must have some
vocabulary what you must know to learn this language, simply in
programming, there is a specified language what compiler or interpreter can
only understand, this specified code of language is called Programming
Language.
• In simple way which language is used to do a program is called Programming
Language.
Avishek Bhattacharjee
5. What is Compiler?
• Operating System of a system software make a layer which helps to convert
user input codes to machine language codes (0-1) and shows the output by
converting it to the same way to user known language. It’s close to machine.
Hardware
System Software
Compiler
Application Software
Avishek Bhattacharjee
6. History of C
On 1970/1971 C was developed by Dennis Ritchie at AT&T Bell laboratories.
(It was popular after the invention of compiler on 1980.)
Why it is called C?
Ans: Before C(CPL) was born there was B(BCPL). So it was chosen c while working on UNIX operating
system project.
Avishek Bhattacharjee
7. Basic Syntax Rules for C
Programming
• C is a case sensitive language so all C
instructions must be written in lower case
letter.
• All C statement must be end with a
semicolon.
• Whitespace is used in C to describe
blanks and tabs.
• Whitespace is required between
keywords and identifiers.
Avishek Bhattacharjee
10. Some Logical Reasoning
• What if there is once more main function?
The Compiler will get confused where to start
program and give an error.
• What does the & mean in C
Programming?
& is called ampersand, it is often used in scanf
function inside the parentheses after a , (comma)
to show the address of a declaring variable. E.g.
scanf(“%d”, &declaring_variable);
• What is called string?
String is usually a collection of letters, numbers,
symbols under double and triple quotes(“string”).
• Why is it called printf rather than print?
f stands for format here, f means formatting
parameters inside parentheses and read input that
conforms with a format string declared in stdio.h.
Avishek Bhattacharjee
12. KEYWORDS
(A type of predefined reserve words used in Programming)
• Character Set: Set of letters,
alphabets and some special
characters that are valid in c.
• Datatype: Type of a Data.
• Identifiers: Refers to the name what
can help to identify of an certain
entity
• Constant: Const. can be used to
declare constant variables whose
values remain unchanged when
initialized.
• Operator: Operator is a symbol
that operate values or variables.
Avishek Bhattacharjee
13. 32 Keywords in C
auto break char case do continue default const
else double enum extern for goto if float
short int long signed unsigned volatile while register
return typedef union switch void sizeof static struct
Avishek Bhattacharjee
auto break character case do continue default constant else double enum extern for goto if float, short int long
signed, unsigned volatile while register return typedef union switch void sizeof static struct.
Simple Way to remind through this sentence.
15. Explanations of Variable Types
• Local Variable: Those variable is
declared inside the function or
block called Local Variable.
• Global Variable: Declared outside
the function/block.
• Static Variable: Retains value in
multiple functions. Situates local
and other variables.
• Automatic Variable: All variables in
c that are declared inside the block
are called Automatic variable.
• External Variable: External variable
can be shared in multiple c files
declared using extern keyword.
Avishek Bhattacharjee
16. CONSTANTS
Primary Constants Secondary Constants
Avishek Bhattacharjee
Integer Constants(Num)
Real Constants(float)
Character Constants(a,b,c…)
Array: Contiguous memory locations of same data type.
Pointer: Containing a variable memory address.
Structure: Collection of any user defined data type
Union: A data type that allows to store different variables of
different data types in the same memory location.
17. Operators
Arithmetic Increment & Decrement Assignment Logical Bitwise Relational
Avishek Bhattacharjee
+ (Unary Plus)
- (Unary Minus)
*(Multiplication)
/ (Division)
% (Remainder)
++ (Increment)
-- (Decrement)
=
+=
-=
*=
/=
%=
==
>=
<=
&&
(Logical
AND)
||
(Logical
OR)
! (Logical
NOT)
If the relation
is true, it
returns one; if
the relation is
false, it returns
zero.
& (Bitwise
AND)
| (Bitwise OR)
^ (Bitwise
exclusive OR)
~ (Bitwise
Complement)
<< (Shift Left)
>> (Shift Right)
18. Basic Concept of Memory Allocations
• Within computer memory, every stored data item occupies one or more
contiguous memory cell.
• Whenever we declare a variable, the system(compiler) allocates memory
locations to hold the value of variable and variable must have some address
while it gets allocated to memory locations.
• Variable address and assigned value are not same. Let’s see now pointer
concept on next slide to understand properly.
Avishek Bhattacharjee
19. Pointer Concept
What is memory?
• Memory is called as racks or place of
locations. Each and every variable,
compiler allocates a memory of some
space. Memory Address
variable1
variable2
variable3
What is pointer?
• Pointer is what contains the
address of a variable allocated to a
memory location. It can be
changed anytime. See the previous
figure that pointer 1 is containing
2600 after it contains 2700, but
mind that a pointer can’t contain
both variable address at a time.
Pointer 1 2600
Pointer 1 2700
Pointer 3 2800
Avishek Bhattacharjee
20. Pointer Expression
• An integer can add or subtract from a pointer.
• Subtract one pointer to another but addition of two pointer is not allowed in
c.
a. Explanations: Suppose p1 and p2 are two pointers, the following
statements are valid;
b. (p1-p2); *p1(address of p1)+2; *p2-3
Avishek Bhattacharjee
21. Storing memory layout for c
1. Text Segment: Code Segment or some text segment containing
instructions situated under heap and stack shown on the pic,
read-only.
2. Initialized Data Segment: Simple data segment containing of
global and static variable of the virtual address place.
3. Uninitialized Data Segment: BSS[Block started by symbol]
another name, start at the end of text segment and all previously
declared variables initialized to zero without any clear
initialization in source.
4. Stack: adjoined the heap area and grew in the opposite direction
and exhaust free memory.
5. Heap: the segment where dynamic memory allocation usually
takes place. The heap area begins at the end of the BSS segment
and grows to larger addresses from there.
Avishek Bhattacharjee
22. Dynamic Memory Locations
Theory with logics
• Every data in nature is dynamic, so we have already known that when we
declare a variable, compiler must allocate some place to memory.
• On the array definition, we know that array means contiguous memory
locations of same data types, if we consider array as variable which value is
integer or float or double then it will take some place and the value what is
assigned will be the storage space for a compiler time of entire memory. So
if variables are changing or static in nature then its memory locations are
dynamic that means it’s changing as per time of compilation.
Avishek Bhattacharjee
23. Memory Allocations Functions
• malloc : - (Allocates requested number of bytes and returns pointer to the first byte
of the allocated space.)
• calloc : - (Allocates space for an array of elements, and initialize them to zero and
returns a pointer to the memory.)
• free : - (Frees previously allocated space.)
• realloc : - (Modifies the previously allocated space.)
A block of memory of specified size can be allocated or reserved using malloc and
returns a pointer type of void.
Pointer type= (type*)malloc(byte_size)); ex: (int*)malloc(100*size of(int));
Avishek Bhattacharjee
24. 80001 80005 80009
In c programming, we are often used dynamic memory locations
techniques to safe wastage of memory space.
X2
x[3]
x[1] x[2]
X1 X3
x[0]
80005
80009
80013
80017
80021
Avishek Bhattacharjee
Variable A
Variable B
Variable C
Variable D
A Block of memory is reserved
here through malloc function and
you can see (p) the pointer type of
void returns here and it’s pointed
through it.
p
Here calloc function is
used and all elements
are initialized to zero
and a pointer returns
to the memory.
25. Array
• Array is a collection of same data types located in contiguous memory locations.
Suppose there is arr[10] that means n(number of indices or elements)=10 so if we
start from 0 so we will get upto 9(0,1,2…,9) here.
Start Address+ index*number of bytes
If the above element is int, so size is 4. we can say a2= a1+0*4
Avishek Bhattacharjee
a1 a2 a3
Index :-0 Index :-1 Index :-2