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

PDF
Develop Embedded Software Module-Session 2
DOCX
Qust & ans inc
PDF
175035 cse lab-05
PPTX
Python programming workshop session 2
PPTX
Python programming workshop session 4
PDF
Programming with c language practical manual
ODP
Aspect-Oriented Technologies
PPTX
Python workshop session 6
Develop Embedded Software Module-Session 2
Qust & ans inc
175035 cse lab-05
Python programming workshop session 2
Python programming workshop session 4
Programming with c language practical manual
Aspect-Oriented Technologies
Python workshop session 6

What's hot (20)

PPTX
Python programming workshop session 3
PPTX
C Programming Language
DOCX
Lab. Programs in C
PPT
PDF
Aptitute question papers in c
DOCX
Java level 1 Quizzes
PPTX
Advance python programming
PPT
C++ Language
PPTX
Python Exception Handling
PPT
Control Statements, Array, Pointer, Structures
PDF
02. functions & introduction to class
PPTX
Python-oop
PDF
ARIC Team Seminar
PDF
VTU PCD Model Question Paper - Programming in C
PPTX
Technical aptitude Test 1 CSE
PPTX
C programming slide c03
PDF
PECCS 2014
PDF
CP Handout#9
PDF
Functional Programming Patterns (BuildStuff '14)
Python programming workshop session 3
C Programming Language
Lab. Programs in C
Aptitute question papers in c
Java level 1 Quizzes
Advance python programming
C++ Language
Python Exception Handling
Control Statements, Array, Pointer, Structures
02. functions & introduction to class
Python-oop
ARIC Team Seminar
VTU PCD Model Question Paper - Programming in C
Technical aptitude Test 1 CSE
C programming slide c03
PECCS 2014
CP Handout#9
Functional Programming Patterns (BuildStuff '14)
Ad

Viewers also liked (6)

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

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

PDF
Embedded C The IoT Academy
PDF
VIT351 Software Development VI Unit3
PPTX
Pointers
PDF
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
PPTX
Pointers in c v5 12102017 1
PPTX
Pointers in c language
PPTX
Unit 8. Pointers
PDF
Embedded C
PDF
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
DOCX
08-Pointers.docx An array is a linear data structure
PDF
c programming
PPT
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
PPT
13092119343434343432232323121211213435554
PPT
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
PPTX
Ponters
PDF
Pointers are one of the core components of the C programming language.
PPTX
PTInstitute - Syllabus of Embedded System Training in Bangalore
PPT
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
PPT
Pointer in C
Embedded C The IoT Academy
VIT351 Software Development VI Unit3
Pointers
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Pointers in c v5 12102017 1
Pointers in c language
Unit 8. Pointers
Embedded C
Microcontroladores: Programación en C para microcontroladores con AVR Butterf...
08-Pointers.docx An array is a linear data structure
c programming
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
13092119343434343432232323121211213435554
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Ponters
Pointers are one of the core components of the C programming language.
PTInstitute - Syllabus of Embedded System Training in Bangalore
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Pointer in C

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Trump Administration's workforce development strategy
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
master seminar digital applications in india
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
O7-L3 Supply Chain Operations - ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Structure & Organelles in detailed.
Trump Administration's workforce development strategy
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Complications of Minimal Access Surgery at WLH
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Orientation - ARALprogram of Deped to the Parents.pptx
RMMM.pdf make it easy to upload and study
master seminar digital applications in india
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

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