Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Typing Speed: 18

Muhammed shafi
shafi3949@gmail.com
Shafi breeze
Shafi breeze
in.linkedin.com/in/profilena
me
9961073949
TOPIC

Pointer in C
What Are Pointers?
A pointer is a variable whose value is the
address of another variable, i.e., direct
address of the memory location
How to use Pointers?
• There are few important operations, which we
will do with the help of pointers very frequently.
(a) we define a pointer variable (b) assign the
address of a variable to a pointer and (c) finally
access the value at the address available in the
pointer variable. This is done by using unary
operator * that returns the value of the variable
located at the address specified by its operand.
Following example makes use of these
operations:
Example of Pointers
•

#include <stdio.h>

•
•
•
•

int main ()
{
int var = 20; /* actual variable declaration */
int *ip;
/* pointer variable declaration */

•

ip = &var; /* store address of var in pointer variable*/

•

printf("Address of var variable: %xn", &var );

•
•

/* address stored in pointer variable */
printf("Address stored in ip variable: %xn", ip );

•
•

/* access the value using the pointer */
printf("Value of *ip variable: %dn", *ip );

•
•

return 0;

}
When the above code is compiled and executed, it produces
result something as follow
Address of var variable: bffd8b3c
Address stored in ip variable: bffd8b3c
Value of *ip variable: 20
NULL Pointers in C
It is always a good practice to assign a NULL
value to a pointer variable in case you do not
have exact address to be assigned. This is
done at the time of variable declaration. A
pointer that is assigned NULL is called a null
pointer.
Example of NULL pointer
#include <stdio.h>
int main ()
{
int *ptr = NULL;
printf("The value of ptr is : %xn", ptr );
return 0;
}
Out put:The value of ptr is 0
THE END
Create by Shafi
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Pointer in C

  • 2.
    Disclaimer: This presentationis prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3.
    Typing Speed: 18 Muhammedshafi shafi3949@gmail.com Shafi breeze Shafi breeze in.linkedin.com/in/profilena me 9961073949
  • 4.
  • 5.
    What Are Pointers? Apointer is a variable whose value is the address of another variable, i.e., direct address of the memory location
  • 6.
    How to usePointers? • There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand. Following example makes use of these operations:
  • 7.
    Example of Pointers • #include<stdio.h> • • • • int main () { int var = 20; /* actual variable declaration */ int *ip; /* pointer variable declaration */ • ip = &var; /* store address of var in pointer variable*/ • printf("Address of var variable: %xn", &var ); • • /* address stored in pointer variable */ printf("Address stored in ip variable: %xn", ip ); • • /* access the value using the pointer */ printf("Value of *ip variable: %dn", *ip ); • • return 0; }
  • 8.
    When the abovecode is compiled and executed, it produces result something as follow Address of var variable: bffd8b3c Address stored in ip variable: bffd8b3c Value of *ip variable: 20
  • 9.
    NULL Pointers inC It is always a good practice to assign a NULL value to a pointer variable in case you do not have exact address to be assigned. This is done at the time of variable declaration. A pointer that is assigned NULL is called a null pointer.
  • 10.
    Example of NULLpointer #include <stdio.h> int main () { int *ptr = NULL; printf("The value of ptr is : %xn", ptr ); return 0; } Out put:The value of ptr is 0
  • 11.
  • 12.
    Contact Us Emarald Mall(Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550