Pointer in C
Pointer
syntax:- type *name
Declaration:- int *aoi;
//int is a type of pointer
//*aoi is a pointer variable.
program to print the address of variable using unary operator.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int i,j;
float f;
char p[20];
clrscr();
i=50;
j=60;
printf("\n The value of i is= %d",i);
printf("\n The address of i is= %u",&i);
printf("\n The value of j is= %d",j);
printf("\n The address of j is= %u",&j);
getch();
}
//name pointer:- value of variable through address.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
int i,j;
float f;
char name[20];
clrscr();
i=50;
j=60;
printf("\n The value i is= %d",i);
printf("\n The value i through address is= %d",*(&i));
printf("\n The address i is= %u",&i);
printf("\n The value j is= %d",j);
printf("\n The value j through address is= %d",*(&j));
printf("\n The address j is= %u",&j);
printf("\n The value float is= %f",dec);
printf("\n The value float through address is= %f",*(&dec));
printf("\n The address float dec is= %u",&dec);
printf("\n The value char name is= %s",name);
printf("\n The value of name through address is= %s",*(&name));
printf("\n The address char name is= %u",&name);
getch();
}
//program to create a pointer variable using your name and use it.
#include<stdio.h>
#include<conio.h>
main()
{
int i, *pankaj; //*pankaj store the address.
clrscr();
i=50;
pankaj=&i;
printf("\n The value of i is %d",&i);
printf("\n The value of i through addres is%d",*pankaj);
printf("\n The address of i is %u",pankaj);
*pankaj=*pankaj+20;
printf("\n the original value is %d",i);
printf("\n the updated value is %d"*pankaj);
getch();
}
// pankaj shows the address of variable.
// *pankaj shows the value of variable.
// *pankaj+20 shows the updated value of variable.
//program to use pointer as an Array .
Note:-
"&" (uniary operator) //returns only one operand
m=&count; //m has the address of count.
q=*m; //q has the value of count. //q recieves the value at address m.
No comments:
Post a Comment