SlideShare a Scribd company logo
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 1
Session 3
Developing Software
Module
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Agenda
Session 1
History of C
Fundamentals of C
Data Types
Variables, Constants and Arrays
Keywords
Decision Control (if-else)
Session 2
Loops
Functions (Overview)
Arrays
Session 3
Pointers & String
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 2
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Strings
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 3
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Definition


Character Arrays and Strings
Strings:
Are enclosed in double quotes "string"
Are terminated by a null character '0'
Must be manipulated as arrays of characters (treated
element by element)
May be initialized with a string literal
Strings are arrays of char whose last element is a null
character '0' with an ASCII value of 0. C has no native
string data type, so strings must always be treated as
character arrays.
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 4
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Syntax
Example


Creating a String Character Array
char str1[10]; //Holds 9 characters plus '0'
char str2[6]; //Holds 5 characters plus '0'
char arrayName[length];
Strings are created like any other array of char:
length must be one larger than the length of the string to
accommodate the terminating null character '0'
A char array with n elements holds strings with n-1 char
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 5
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example
Syntax


How to Initialize a String at Declaration
char str1[] = "Microchip"; //10 chars "Microchip0"
char str2[6] = "Hello"; //6 chars "Hello0"
//Alternative string declaration – size required
char str3[4] = {'P', 'I', 'C', '0'};
char arrayName[] = "Microchip";
Character arrays may be initialized with string literals:
Array size is not required
Size automatically determined by length of string
NULL character '0' is automatically appended
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 6
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Syntax
Example
How to Initialize a String in Code
str[0] = 'H';
str[1] = 'e';
str[2] = 'l';
str[3] = 'l';
str[4] = 'o';
str[5] = '0';
arrayName[0] = char1;
arrayName[1] = char2;
arrayName[n] = '0';
In code, strings must be initialized element by element:
Null character '0' must be appended manually
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 7
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Comparing Strings
Strings cannot be compared using relational operators
(==, !=, etc.)
Must use standard C library string manipulation
functions
strcmp() returns 0 if strings equal
char str[] = "Hello";
if (!strcmp( str, "Hello"))
printf("The string is "%s".n", str);
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 8
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Data Pointers
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 9
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role


A Variable's Address versus A Variable's Value
In some situations, we will want to work with a variable's
address in memory, rather than the value it contains…
005A
Address
16-bit Data Memory
(RAM)
0x0802
0x0804
0x0806
0x0808
0x0800
x
Variable stored
at Address
0123
DEAD
BEEF
F00D
0456 0x080A
Variable name
from C code
int x;
Value of
variable x
= 0x0123
Address of
variable x
= 0x0802
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 10
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
What are pointers?
A pointer is a variable or constant that holds the
address of another variable or function
FFFF
Address
16-bit Data Memory
(RAM)
0x0802
0x0804
0x0806
0x0808
0x0800
x
p
Variable at
Address
0123
FFFF
0802
FFFF
FFFF 0x080A
Integer Variable:
Pointer Variable:
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 11
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role


What do they do?
A pointer allows us to indirectly access a variable
(just like indirect addressing in assembly language)
005A
Address
16-bit Data Memory
(RAM)
0x0802
0x0804
0x0806
0x0808
0x0800
x 0123
DEAD
0802
F00D
0456 0x080A
p
x = 0x0123;
*p = 0x0123;
Direct Access
via x
Indirect Access
via *p
p points to x
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 12
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example
Syntax


How to Create a Pointer Variable
int *iPtr; // Create a pointer to int
float *fPtr; // Create a pointer to float
type *ptrName;
In the context of a declaration, the * merely indicates that the
variable is a pointer
type is the type of data the pointer may point to
Pointer usually described as “a pointer to type”
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 13
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
To set a pointer to point to another variable, we use the
& operator (address of), and the pointer variable is
used without the dereference operator *:
This assigns the address of the variable x to the
pointer p (p now points to x)
Note: p must be declared to point to the type of x (e.g.
int x; int *p;)


Initialization
p = &x;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 14
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role


Usage
When accessing the variable pointed to by a pointer,
we use the pointer with the dereference operator *:
This assigns to the variable y, the value of what p is
pointing to (x from the last slide)
Using *p, is the same as using the variable it points to
(e.g. x)
y = *p;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 15
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Another Way To Look At The Syntax
&x is a constant pointer
It represents the address of x
The address of x will never change
p is a variable pointer to int
It can be assigned the address of any int
It may be assigned a new address any time
int x, *p; //int and a pointer to int
p = &x; //Assign p the address of x
*p = 5; //Same as x = 5;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 16
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Another Way To Look At The Syntax
*p represents the data pointed to by p
*p may be used anywhere you would use x
* is the dereference operator, also called the
indirection operator
In the pointer declaration, the only significance of * is
to indicate that the variable is a pointer rather than an
ordinary variable
int x, *p; //1 int, 1 pointer to int
p = &x; //Assign p the address of x
*p = 5; //Same as x = 5;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 17
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
x
y
p
Variable at
Address
0x08C8
0000
0000
0000
0000
0000
0000
0000
0000
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 18
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
DEAD
0000
0000
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 19
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
DEAD
BEEF
0000
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 20
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
DEAD
BEEF
08BC
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 21
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
0100
BEEF
08BC
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 22
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
0100
BEEF
08BE
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 23
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


How Pointers Work
Address
16-bit Data Memory
(RAM)
0x08BC
0x08BE
0x08C0
0x08C2
0x08C4
0x08C6
0x08BA
x
y
p
Variable at
Address
0x08C8
0000
0100
0200
08BE
0000
0000
0000
0000
{
int x, y;
int *p;
x = 0xDEAD;
y = 0xBEEF;
p = &x;
*p = 0x0100;
p = &y;
*p = 0x0200;
}
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 24
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role


Post-Increment/Decrement Syntax Rule
Care must be taken with respect to operator precedence
when doing pointer arithmetic:
Syntax Operation Description by Example
Post-Increment
data pointed to
by Pointer
(*p)++
Post-Increment
Pointer
*p++
*(p++)
z = (*p)++;
is equivalent to:
z = *p;
*p = *p + 1;
z = *(p++);
is equivalent to:
z = *p;
p = p + 1;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 25
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Post-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0800
0000
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(p++);
y = 5 + (*p)++;
}
Remember:
*(p++) is the same as *p++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 26
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Post-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0800
0006
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(p++);
y = 5 + (*p)++;
}
Remember:
*(p++) is the same as *p++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 27
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Post-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0802
0006
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(p++);
y = 5 + (*p)++;
}
Remember:
*(p++) is the same as *p++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 28
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Post-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0802
0007
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(p++);
y = 5 + (*p)++;
}
Remember:
*(p++) is the same as *p++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 29
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Post-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0003
0003
0802
0007
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(p++);
y = 5 + (*p)++;
}
Remember:
*(p++) is the same as *p++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 30
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role


Pre-Increment/Decrement Syntax Rule
Care must be taken with respect to operator
precedence when doing pointer arithmetic:
Syntax Operation Description by Example
Pre-Increment
data pointed to
by Pointer
++(*p)
Pre-Increment
Pointer
++*p
*(++p)
z = ++(*p);
is equivalent to:
*p = *p + 1;
z = *p;
z = *(++p);
is equivalent to:
p = p + 1;
z = *p;
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 31
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Pre-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0800
0000
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(++p);
y = 5 + ++(*p);
}
Remember:
*(++p) is the same as *++p
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 32
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Pre-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0802
0000
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(++p);
y = 5 + ++(*p);
}
Remember:
*(++p) is the same as *++p
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 33
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Pre-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0002
0003
0802
0007
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(++p);
y = 5 + ++(*p);
}
Remember:
*(++p) is the same as *++p
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 34
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Pre-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0003
0003
0802
0007
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(++p);
y = 5 + ++(*p);
}
Remember:
*(++p) is the same as *++p
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 35
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Pre-Increment / Decrement Syntax
Address
16-bit Data Memory
(RAM)
0x0800
0x0802
0x0804
0x0806
0x0808
0x080A
0x07FE
x[0]
x[1]
x[2]
0x080C
0000
0001
0003
0003
0802
0008
0000
0000
p
y
{
int x[3] = {1,2,3};
int y;
int *p = &x;
y = 5 + *(++p);
y = 5 + ++(*p);
}
Remember:
*(++p) is the same as *++p
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 36
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
The parentheses determine what gets incremented/
decremented:


Pre- and Post- Increment/Decrement Summary
Modify the pointer itself
*(++p) or *++p and *(p++) or *p++
Modify the value pointed to by the pointer
++(*p) and (*p)++
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 37
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Example


Initialization Tip
If a pointer isn't initialized to a specific address when it
is created, it is a good idea to initialize it as NUL
(pointing to nowhere)
This will prevent it from unintentionally corrupting a
memory location if it is accidentally used before it is
initialized
int *p = NUL;
NULL is the character '0' but NUL is the value of a
pointer that points to nowhere
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 38
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Conclusion
Pointers are variables that hold the address of other
variables.
Pointers make it possible for the program to change
which variable is acted on by a particular line of code .
Incrementing and decrementing pointers will modify
the value in multiples of the size of the type they point
to.
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 39
Training Of Trainers (TOT) program on
Embedded Software Engineer Job role
Thank you!
www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 40

More Related Content

What's hot

Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
Abdul Haseeb
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
RTS Tech
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
Saket Pathak
 
C++ Programming
C++ ProgrammingC++ Programming
Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
Pantech ProEd Pvt Ltd
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 QuizzesSteven Luo
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
Jagdish Chavan
 
C++ Language
C++ LanguageC++ Language
C++ Language
Syed Zaid Irshad
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
RTS Tech
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
indra Kishor
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
Haresh Jaiswal
 
Python-oop
Python-oopPython-oop
Python-oop
RTS Tech
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
Sujata Regoti
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
trupti1976
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
Scott Wlaschin
 

What's hot (20)

Python programming workshop session 3
Python programming workshop session 3Python programming workshop session 3
Python programming workshop session 3
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
C++ Programming
C++ ProgrammingC++ Programming
C++ Programming
 
Qno 1 (f)
Qno 1 (f)Qno 1 (f)
Qno 1 (f)
 
Aptitute question papers in c
Aptitute question papers in cAptitute question papers in c
Aptitute question papers in c
 
Java level 1 Quizzes
Java level 1 QuizzesJava level 1 Quizzes
Java level 1 Quizzes
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Control Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, StructuresControl Statements, Array, Pointer, Structures
Control Statements, Array, Pointer, Structures
 
02. functions & introduction to class
02. functions & introduction to class02. functions & introduction to class
02. functions & introduction to class
 
Python-oop
Python-oopPython-oop
Python-oop
 
ARIC Team Seminar
ARIC Team SeminarARIC Team Seminar
ARIC Team Seminar
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Technical aptitude Test 1 CSE
Technical aptitude Test 1 CSETechnical aptitude Test 1 CSE
Technical aptitude Test 1 CSE
 
C programming slide c03
C programming slide c03C programming slide c03
C programming slide c03
 
PECCS 2014
PECCS 2014PECCS 2014
PECCS 2014
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 

Viewers also liked

Engineer Jobs Singapore-Software Engineer
Engineer Jobs Singapore-Software EngineerEngineer Jobs Singapore-Software Engineer
Engineer Jobs Singapore-Software Engineer
Vincent Siew
 
Designing a Training Program: A Training Manager's Dilemma
Designing a Training Program: A Training Manager's DilemmaDesigning a Training Program: A Training Manager's Dilemma
Designing a Training Program: A Training Manager's Dilemma
anam_patel
 
Career development ppt
Career development pptCareer development ppt
Career development ppt
Nancy Erskine-Sackey
 
Case study: problem with john from project management
Case study: problem with john from project management Case study: problem with john from project management
Case study: problem with john from project management
rajustalization4123106
 
Bpr Case Study
Bpr Case StudyBpr Case Study
Bpr Case Study
SRM University
 
Career management ppt
Career management pptCareer management ppt
Career management ppt
Nilanjan Bhaumik
 

Viewers also liked (6)

Engineer Jobs Singapore-Software Engineer
Engineer Jobs Singapore-Software EngineerEngineer Jobs Singapore-Software Engineer
Engineer Jobs Singapore-Software Engineer
 
Designing a Training Program: A Training Manager's Dilemma
Designing a Training Program: A Training Manager's DilemmaDesigning a Training Program: A Training Manager's Dilemma
Designing a Training Program: A Training Manager's Dilemma
 
Career development ppt
Career development pptCareer development ppt
Career development ppt
 
Case study: problem with john from project management
Case study: problem with john from project management Case study: problem with john from project management
Case study: problem with john from project management
 
Bpr Case Study
Bpr Case StudyBpr Case Study
Bpr Case Study
 
Career management ppt
Career management pptCareer management ppt
Career management ppt
 

Similar to Develop Embedded Software Module-Session 3

C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
neosphere
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
RamprakashSingaravel1
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
DinobandhuThokdarCST
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
Gaurav Verma
 
See through C
See through CSee through C
See through C
Tushar B Kute
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
Yuvraj994432
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
vrickens
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)bolovv
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
moduledesign
 
c.ppt
c.pptc.ppt
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTREC Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
jatin batra
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
moduledesign
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
Abdul Haseeb
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
rajatryadav22
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
Vikash Dhal
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
KrishanPalSingh39
 

Similar to Develop Embedded Software Module-Session 3 (20)

C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
 
dinoC_ppt.pptx
dinoC_ppt.pptxdinoC_ppt.pptx
dinoC_ppt.pptx
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Embedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontrollerEmbedded C programming based on 8051 microcontroller
Embedded C programming based on 8051 microcontroller
 
See through C
See through CSee through C
See through C
 
additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Advanced+pointers
Advanced+pointersAdvanced+pointers
Advanced+pointers
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
c.ppt
c.pptc.ppt
c.ppt
 
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTREC Programming Training In Ambala ! BATRA COMPUTER CENTRE
C Programming Training In Ambala ! BATRA COMPUTER CENTRE
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Python programming workshop session 1
Python programming workshop session 1Python programming workshop session 1
Python programming workshop session 1
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 

Recently uploaded

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 

Recently uploaded (20)

How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 

Develop Embedded Software Module-Session 3

  • 1. Training Of Trainers (TOT) program on Embedded Software Engineer Job role www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 1 Session 3 Developing Software Module
  • 2. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Agenda Session 1 History of C Fundamentals of C Data Types Variables, Constants and Arrays Keywords Decision Control (if-else) Session 2 Loops Functions (Overview) Arrays Session 3 Pointers & String www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 2
  • 3. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Strings www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 3
  • 4. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Definition 
 Character Arrays and Strings Strings: Are enclosed in double quotes "string" Are terminated by a null character '0' Must be manipulated as arrays of characters (treated element by element) May be initialized with a string literal Strings are arrays of char whose last element is a null character '0' with an ASCII value of 0. C has no native string data type, so strings must always be treated as character arrays. www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 4
  • 5. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Syntax Example 
 Creating a String Character Array char str1[10]; //Holds 9 characters plus '0' char str2[6]; //Holds 5 characters plus '0' char arrayName[length]; Strings are created like any other array of char: length must be one larger than the length of the string to accommodate the terminating null character '0' A char array with n elements holds strings with n-1 char www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 5
  • 6. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example Syntax 
 How to Initialize a String at Declaration char str1[] = "Microchip"; //10 chars "Microchip0" char str2[6] = "Hello"; //6 chars "Hello0" //Alternative string declaration – size required char str3[4] = {'P', 'I', 'C', '0'}; char arrayName[] = "Microchip"; Character arrays may be initialized with string literals: Array size is not required Size automatically determined by length of string NULL character '0' is automatically appended www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 6
  • 7. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Syntax Example How to Initialize a String in Code str[0] = 'H'; str[1] = 'e'; str[2] = 'l'; str[3] = 'l'; str[4] = 'o'; str[5] = '0'; arrayName[0] = char1; arrayName[1] = char2; arrayName[n] = '0'; In code, strings must be initialized element by element: Null character '0' must be appended manually www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 7
  • 8. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Comparing Strings Strings cannot be compared using relational operators (==, !=, etc.) Must use standard C library string manipulation functions strcmp() returns 0 if strings equal char str[] = "Hello"; if (!strcmp( str, "Hello")) printf("The string is "%s".n", str); www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 8
  • 9. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Data Pointers www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 9
  • 10. Training Of Trainers (TOT) program on Embedded Software Engineer Job role 
 A Variable's Address versus A Variable's Value In some situations, we will want to work with a variable's address in memory, rather than the value it contains… 005A Address 16-bit Data Memory (RAM) 0x0802 0x0804 0x0806 0x0808 0x0800 x Variable stored at Address 0123 DEAD BEEF F00D 0456 0x080A Variable name from C code int x; Value of variable x = 0x0123 Address of variable x = 0x0802 www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 10
  • 11. Training Of Trainers (TOT) program on Embedded Software Engineer Job role What are pointers? A pointer is a variable or constant that holds the address of another variable or function FFFF Address 16-bit Data Memory (RAM) 0x0802 0x0804 0x0806 0x0808 0x0800 x p Variable at Address 0123 FFFF 0802 FFFF FFFF 0x080A Integer Variable: Pointer Variable: www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 11
  • 12. Training Of Trainers (TOT) program on Embedded Software Engineer Job role 
 What do they do? A pointer allows us to indirectly access a variable (just like indirect addressing in assembly language) 005A Address 16-bit Data Memory (RAM) 0x0802 0x0804 0x0806 0x0808 0x0800 x 0123 DEAD 0802 F00D 0456 0x080A p x = 0x0123; *p = 0x0123; Direct Access via x Indirect Access via *p p points to x www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 12
  • 13. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example Syntax 
 How to Create a Pointer Variable int *iPtr; // Create a pointer to int float *fPtr; // Create a pointer to float type *ptrName; In the context of a declaration, the * merely indicates that the variable is a pointer type is the type of data the pointer may point to Pointer usually described as “a pointer to type” www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 13
  • 14. Training Of Trainers (TOT) program on Embedded Software Engineer Job role To set a pointer to point to another variable, we use the & operator (address of), and the pointer variable is used without the dereference operator *: This assigns the address of the variable x to the pointer p (p now points to x) Note: p must be declared to point to the type of x (e.g. int x; int *p;) 
 Initialization p = &x; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 14
  • 15. Training Of Trainers (TOT) program on Embedded Software Engineer Job role 
 Usage When accessing the variable pointed to by a pointer, we use the pointer with the dereference operator *: This assigns to the variable y, the value of what p is pointing to (x from the last slide) Using *p, is the same as using the variable it points to (e.g. x) y = *p; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 15
  • 16. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Another Way To Look At The Syntax &x is a constant pointer It represents the address of x The address of x will never change p is a variable pointer to int It can be assigned the address of any int It may be assigned a new address any time int x, *p; //int and a pointer to int p = &x; //Assign p the address of x *p = 5; //Same as x = 5; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 16
  • 17. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Another Way To Look At The Syntax *p represents the data pointed to by p *p may be used anywhere you would use x * is the dereference operator, also called the indirection operator In the pointer declaration, the only significance of * is to indicate that the variable is a pointer rather than an ordinary variable int x, *p; //1 int, 1 pointer to int p = &x; //Assign p the address of x *p = 5; //Same as x = 5; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 17
  • 18. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } x y p Variable at Address 0x08C8 0000 0000 0000 0000 0000 0000 0000 0000 www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 18
  • 19. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 DEAD 0000 0000 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 19
  • 20. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 DEAD BEEF 0000 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 20
  • 21. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 DEAD BEEF 08BC 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 21
  • 22. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 0100 BEEF 08BC 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 22
  • 23. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 0100 BEEF 08BE 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 23
  • 24. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 How Pointers Work Address 16-bit Data Memory (RAM) 0x08BC 0x08BE 0x08C0 0x08C2 0x08C4 0x08C6 0x08BA x y p Variable at Address 0x08C8 0000 0100 0200 08BE 0000 0000 0000 0000 { int x, y; int *p; x = 0xDEAD; y = 0xBEEF; p = &x; *p = 0x0100; p = &y; *p = 0x0200; } www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 24
  • 25. Training Of Trainers (TOT) program on Embedded Software Engineer Job role 
 Post-Increment/Decrement Syntax Rule Care must be taken with respect to operator precedence when doing pointer arithmetic: Syntax Operation Description by Example Post-Increment data pointed to by Pointer (*p)++ Post-Increment Pointer *p++ *(p++) z = (*p)++; is equivalent to: z = *p; *p = *p + 1; z = *(p++); is equivalent to: z = *p; p = p + 1; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 25
  • 26. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Post-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0800 0000 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(p++); y = 5 + (*p)++; } Remember: *(p++) is the same as *p++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 26
  • 27. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Post-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0800 0006 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(p++); y = 5 + (*p)++; } Remember: *(p++) is the same as *p++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 27
  • 28. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Post-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0802 0006 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(p++); y = 5 + (*p)++; } Remember: *(p++) is the same as *p++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 28
  • 29. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Post-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0802 0007 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(p++); y = 5 + (*p)++; } Remember: *(p++) is the same as *p++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 29
  • 30. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Post-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0003 0003 0802 0007 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(p++); y = 5 + (*p)++; } Remember: *(p++) is the same as *p++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 30
  • 31. Training Of Trainers (TOT) program on Embedded Software Engineer Job role 
 Pre-Increment/Decrement Syntax Rule Care must be taken with respect to operator precedence when doing pointer arithmetic: Syntax Operation Description by Example Pre-Increment data pointed to by Pointer ++(*p) Pre-Increment Pointer ++*p *(++p) z = ++(*p); is equivalent to: *p = *p + 1; z = *p; z = *(++p); is equivalent to: p = p + 1; z = *p; www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 31
  • 32. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Pre-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0800 0000 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(++p); y = 5 + ++(*p); } Remember: *(++p) is the same as *++p www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 32
  • 33. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Pre-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0802 0000 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(++p); y = 5 + ++(*p); } Remember: *(++p) is the same as *++p www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 33
  • 34. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Pre-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0002 0003 0802 0007 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(++p); y = 5 + ++(*p); } Remember: *(++p) is the same as *++p www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 34
  • 35. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Pre-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0003 0003 0802 0007 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(++p); y = 5 + ++(*p); } Remember: *(++p) is the same as *++p www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 35
  • 36. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Pre-Increment / Decrement Syntax Address 16-bit Data Memory (RAM) 0x0800 0x0802 0x0804 0x0806 0x0808 0x080A 0x07FE x[0] x[1] x[2] 0x080C 0000 0001 0003 0003 0802 0008 0000 0000 p y { int x[3] = {1,2,3}; int y; int *p = &x; y = 5 + *(++p); y = 5 + ++(*p); } Remember: *(++p) is the same as *++p www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 36
  • 37. Training Of Trainers (TOT) program on Embedded Software Engineer Job role The parentheses determine what gets incremented/ decremented: 
 Pre- and Post- Increment/Decrement Summary Modify the pointer itself *(++p) or *++p and *(p++) or *p++ Modify the value pointed to by the pointer ++(*p) and (*p)++ www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 37
  • 38. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Example 
 Initialization Tip If a pointer isn't initialized to a specific address when it is created, it is a good idea to initialize it as NUL (pointing to nowhere) This will prevent it from unintentionally corrupting a memory location if it is accidentally used before it is initialized int *p = NUL; NULL is the character '0' but NUL is the value of a pointer that points to nowhere www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 38
  • 39. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Conclusion Pointers are variables that hold the address of other variables. Pointers make it possible for the program to change which variable is acted on by a particular line of code . Incrementing and decrementing pointers will modify the value in multiples of the size of the type they point to. www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 39
  • 40. Training Of Trainers (TOT) program on Embedded Software Engineer Job role Thank you! www.emtech.in 24x7 Helpline +91 92120 88881 info@emtech.in 40