pointer in c

12

Category:

Education


1 download

DESCRIPTION

Pointer in C

TRANSCRIPT

Page 1: Pointer in C
Page 2: Pointer in C

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

Page 3: Pointer in C

Muhammed [email protected] breezeShafi breezein.linkedin.com/in/

profilename9961073949

Typing Speed: 18

Page 4: Pointer in C

TOPIC

Pointer in C

Page 5: 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

Page 6: Pointer in C

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:

Page 7: Pointer in C

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: %x\n", &var );

• /* address stored in pointer variable */• printf("Address stored in ip variable: %x\n", ip );

• /* access the value using the pointer */• printf("Value of *ip variable: %d\n", *ip );

• return 0;• }

Page 8: Pointer in C

When the above code is compiled and executed, it produces result something as follow

Address of var variable: bffd8b3cAddress stored in ip variable: bffd8b3cValue of *ip variable: 20

Page 9: Pointer in C

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.

Page 10: Pointer in C

Example of NULL pointer#include <stdio.h>int main (){ int *ptr = NULL; printf("The value of ptr is : %x\n", ptr ); return 0;}

Out put:-The value of ptr is 0

Page 11: Pointer in C

THE END

Create by

Shafi

Page 12: Pointer in C

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

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

Start up VillageEranakulam,Kerala, India.

Email: [email protected]