0% found this document useful (0 votes)
56 views

Memory Management & Pointer in C

Uploaded by

Đức Mạnh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Memory Management & Pointer in C

Uploaded by

Đức Mạnh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

FPT SOFTWARE WORKFORCE ASSURANCE

Memory management &


Pointer in C

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1


Objectives

▪ Memory layout
▪ Variable and memory location
▪ Pointer variable
▪ Assigning values to a pointer
▪ Memory allocation for a pointer
▪ Pointer arithmetic
▪ Pass by Value & Pass by Reference

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1


Memory layout

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 3 09e-BM/DT/FSOFT v1/1


Variable and memory location

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 4 09e-BM/DT/FSOFT v1/1


Variable and memory location

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 5 09e-BM/DT/FSOFT v1/1


Pointer variable

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 6 09e-BM/DT/FSOFT v1/1


Assigning values to a pointer

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 7 09e-BM/DT/FSOFT v1/1


Memory allocation for a pointer

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 8 09e-BM/DT/FSOFT v1/1


Pointer arithmetic

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 9 09e-BM/DT/FSOFT v1/1


Question

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 10 09e-BM/DT/FSOFT v1/1


Pointer vs Array

Most of the time, pointer and array accesses can be


treated as acting the same, the major exceptions:
1.sizeof operator
2.& operator
3.a string literal initialization of a character array
4.Pointer variable can be assigned a value whereas
array variable cannot be
5.Arithmetic on pointer variable is allowed
6.Array is a collection of similar data types while pointer
variable stores the address of another variable

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 11 09e-BM/DT/FSOFT v1/1


Pointer vs Array

09e-BM/DT/FSOFT
12
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1
Pass by Value?

Swap value of 2
integer variables

A copy of the data is made and stored by way of the name of the
parameter. Any changes to the parameter have NO affect on data in
the calling function.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1
Pass by Value?

a and b value are not changed, their copies are changed only
🡪 Can we change those value after function call?

🡪 We can access to address of those variables

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1


Pass by Reference?

A reference parameter "refers" to the original data in the calling


function.

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 09e-BM/DT/FSOFT v1/1


Q&A

© FPT SOFTWARE – TRAINING MATERIAL – Internal use 16 09e-BM/DT/FSOFT v1/1

You might also like