Download presentation
Presentation is loading. Please wait.
Published byBrittany Small Modified over 6 years ago
1
BILASPUR UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE AND APPLICATION
TOPIC:-POINTER,STRUCTURE POINTER,POINTER TO POINTER GUIDED BY : PRESENTED BY :- JITENDRE SIR SADIL QURESHI
2
POINTER:- A pointer is a Variable Whose Value is The Address of Another Variable i.e., Direct Address of the Memory Location Like Any Variable or Constant, You Must Declare a Pointer Before Using it to Store Any Variable Address. The General Form Of a Pointer Variable Declaration is – type *var-name; Here,Type is the Pointer Base Type; it Must Be a Valid C data type and var-name is the Name of the Pointer Variable. The Asterisk * is Used to Declare a Pointer.
3
Pointers are used frequently in c as they offer number of benefits to the programmer
Pointer are more efficient in handling arrays and data table. Pointer can be used to return multiple values from the function via function argument. Pointer allow c to support dynamic memory management. Pointer reduce length and complicity of programs.
4
Pointer Types Pointer C++ has pointer types for each type of object
Pointers to int objects Pointers to char objects Pointers to user-defined objects (e.g., RationalNumber) Even pointers to pointers Pointers to pointers to int objects
5
Here is the POINTER program to print the address of a variable along with its value
program:- #include <stdio.h> #include <conio.h> main() { char a; int x; float p,q; a= ‘A’; X= 125; P= 10.25; Q= 18.76; printf(“%c is stored at addr %u. \n”, a , &a); printf(“%d is stored at addr %u. \n” , x , &x); Printf(%f is stored at addr %u. \n”, p , &p); Printf(%f is stored at addr %u. \n” ,q , &q); } Output::-- A is stored at addr is stored at addr is stored at addr is stored at addr 4438.
6
Pointer to Pointer What is the output?
7
Pointer to pointer :-- A pointer to pointer is a form of multiple indirection, or a chain of pointer. Normally a pointer contains the address of a variable. When we define a pointer to pointer, the first pointer contain s the address of the second pointer, which points to the location that contains the actual value as shown below. Pointer Pointer Variable address address value
8
When a target is indirectly pointed then value requires that the asterisk operator applied twice as shown in the program POINTER TO POINTER Program:- #include<stdio.h> Int main() Int var; Int *ptr; Int **pptr; Var=3000; /*take the address of var */ Ptr=&var; /*take the address of ptr using address of operator & */ Pptr=&ptr; /*take the value using pptr */ Printf(“value of var=%d\n) ”,var; Printf(“value available at *ptr=%d\n”,*ptr); Printf(“value available at **pptr=%d\n”,**pptr); return 0; } Output:- Value of var=3000 Value available at *ptr=3000 Value available at **pptr=3000
9
C pointer to structure POINTER TO STRUCTURE:
Pointer which store address of structure is called as “pointer to structure” Explanation: Sptr is pointer to structure addres. -> and (*). Both represent the same. These operator are used to access data mamber of structure by using structure’s pointer.
10
Program:- #include<stdio. h> Struct team { char
Program:- #include<stdio.h> Struct team { char *name; int member; char captain [20]; } T1={“india”,11,”dhoni”} , * Sptr = &t1; Int main() Print(“\nteam : %s”, (sptr).name ); Printf(“\nmembers : %d”,sptr ->members ); Printf(“\ncaptain :%s” , (sptr) . Captain ); Return 0; Output :- Team : india Members : 11 Captain : Dhoni
11
THANK YOU VERY MUCH FOR YOUR PATIENCE
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.