Presentation is loading. Please wait.

Presentation is loading. Please wait.

Buy book Online -

Similar presentations


Presentation on theme: "Buy book Online -"— Presentation transcript:

1 Buy book Online - www.icebreakerspublications.com

2

3 Under st anding Pointe r
Definition : Variable store the values. E.g. int i store 5. Pointer is a variable which store address of another variable. E.g. j store address of i , so j is a pointer. Buy book Online -

4 Pointer Declaration <data type> * <pointer name> int * ptr
Syntax : <data type> * <pointer name> Example : int * ptr Buy book Online -

5 Store Address to pointer
Syntax : Pointer-name = & (variable name) Example : j = & i; Buy book Online -

6 Accessing Pointer * pointer-name *j Syntax : Example :
Buy book Online -

7 Example : Pointer #include<stdio.h> #include<conio.h>
int main() { int number =0; int *ptr; printf(“\n Enter number”); scanf(“%d”, &number); Output: Enter number 5 5 is stored at 65524 ptr=&number; //assigning address of number to pointer ptr printf(“\n %d is stored at %u ”, number , ptr); // printing address using %u getch(); return 0; }

8 Pointer With Function (call by reference)
#include<stdio.h> int add (int * , int *); //1. function declaration int * <--pointer int main() { int a=5 , b=6, y; y=Add(&a , &b); // 2. function call passing reference. printf(“addition = %d” , y); return 0; } int add (int * x, int * y) { // 3. function definition int result; result= *x + *y; // *x contain value 5 return result; } Output: addition =11

9 Pointer with Structure
Syntax: Example: struct struct-name struct book { { ---- int price; ---- int pages; ---- char name[ 50 ]; }; }; struct struct-name * pointer-name ; struct book * ptr1; Buy book Online -

10 Exam ucture Example

11 Array of Pointers arr[0] = & i ; arr[1] = & j; arr[2] = & k;
Definition : The way there can be an array of ints or an array of floats, similarly there can be an array of pointers. Since a pointer variable always contains an address, an array of pointers would be nothing but a collection of addresses. Example: int * arr[4] ; arr is array of integer pointers. It contains 4 addresses of integer variables: arr[0] = & i ; arr[1] = & j; arr[2] = & k; arr[3] = & l ; Buy book Online -

12 Pointe r To Pointe r int i , *j , **k ; int i =30 int *j = &i
Observe how the variables j and k have been declared, int i , *j , **k ; Here, i is an ordinary int, j is a pointer to an int (often called an integer pointer), whereas k is a pointer to an integer pointer (often called a pointer to pointer). variable pointer pointer to pointer int i =30 int *j = &i int **k = &j Buy book Online -

13 End of chapter


Download ppt "Buy book Online -"

Similar presentations


Ads by Google