Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

WELCOME TO MY PRESENTATION

ON
INTRODUCTION TO POINTER IN C

PRESENTED TO: MD. SARWAR HOSAIN


ASSISTANT PROFESSOR
DEPT. OF INFORMATION AND COMMUNICATION ENGINEERING
What is a pointer?
A pointer is a derived data type in C. It is built of the
fundamental data types available in C. Pointers contain
memory addresses as their values. Pointers can be used
to access and manipulate data stored in the memory. It
has added power and flexibility to the language.
Pointer offers a number of benefits to the programmers.
It includes:
1. More efficient in handling arrays and data
tables

2. Return multiple values from a function

3. Saves the data storage space in memory

4. Reduces length and complexity of a


program

5. Increase the execution speed and reduce the


program execution time
Memory Cell Address
Understanding Pointer: 0
A computer’s memory is a sequential collection 1
of storage cells. Each cell is commonly known as 2
byte. Since every byte has a unique address
number. Consider the following statement: .
.
int number = 179; .

This statement instructs the system to find a 65,535

location for the integer variable number and puts Number — Variable
the value 179 in that location. Let’s assume that 179 — Value
5000 — Address
the system has chosen the address location 5000
for number. Fig-1: Understanding pointers
Pointers are built on three concepts. They are:
1.Pointer constants : Pointer constants cannot be changed, we can only use them to
store data value.
2. Pointer values : The pointer value (the address of a variable) may change from
one run of the program to another.
3. Pointer variables : The variable that contains a pointer value is called a pointer
variables.
Accessing the address of a variable :
Let us assume a problem that given below: In this program, this
is seen that the
#include <stdio.h> address of x is
void main() given by &x.
{ The & operator can
int x = 125; be remembered as
printf(“%d is stored at address %u.\n”, x, &x); ‘address of’.
}

Output:
125 is stored at address 4434.
Declaring pointer variables:
In C, every variable must be declared for its type. The declaration of a
pointer variable take the following form:
data_type *pt_name;
This tells the compiler three things about the variable pt_name. They are:
• The asterisk (*) tells the variable pt_name.
• pt_name needs a memory location.
• pt_name points to a variable of data_type.
For example:
int *p;/*integer pointer*/
Declare the variable p as a pointer variable that points to an integer data
type.
Pointer declaration style:
int* p;
int *p;
int * p;
Let’s see a pointer code:
#include <stdio.h>
int main()
{
   int *ptr, q;
   q = 50;
   ptr = &q;
   printf("%d is in %u", q, ptr);
   return 0;
}

Output :
50 is in 6356744

Here ptr shows the address of q value


Thank you everybody
Presented by-
Md. Imran Nazir
Dept. of Information and Communication Engineering
Roll – 180601
1st year 2nd semester

You might also like