Which pointer variable pointing to an inactive or dead location, it is called dangling pointer.
Which pointer variable holds the address of the function, it is called function pointer
By using function pointers in C, we can pass a f’n as an argument to another function
syntax : datatype*(*ptr)(); - non parameterized ex: int*(*ptr)(); datatype*(*ptr)(datatype); - > parameterized ex : int*(*ptr)(int);
Written by Call by value, written by address :
i.e, ( function returning pointer (return by address) int *abc() { int a=10; ++ a; return &a; } void main() { int *ptr; ptr = abc(); printf(“n value of a%d”, *ptr); } o/p : value of a : 11(illegal)
{ static int s=5; --s; return &s; } void main() { int *ptr ptr=xyz(); print=xyz(); printf(“n static data: %d”,*ptr);
o/p : static data : 4
{ printf(“welcome abc”); } void main() { void (*ptr)(); // function pointer ptr=&abc; ptr(); //abc(); }
o/p : welcome abc
{ printf(“welcome abc”); } void main() { void(*ptr)(); ptr=&abc; abc(); }
o/p : welcome abc
{ int a=10; ++a; return a; } void main() { int(*ptr)(void); int x; ptr=&xyz; x=ptr(); printf(“value of : %d”,x); }
o/p : value of x : 11
{
static int s=15;
++s;
return &s;
}
}
void main()
{
int*(*ptr)(); // function pointer
int *p; // pointer integer
ptr=&abc;
p=ptr(); int
abc(int x)
{
static int s;
s=++x;
return &s;
}
void xyz(int i)
{
printf(“n static data is xyz : %d”,i);
}
void fun ptr(int * myptr)
{
myptr= 88;
}
void main()
{
int *(*ptr) (int);
int +*p;
int +a;
ptr=&abc;
p=ptr(10);
xyz(ptr(20));
funptr(ptr(30));
a=*p;
ptrinf(“n static data in main : %d”,a);
static data in main 88. 35
}
void abc()
{
printf(“Hello abc”);
}
void main()
{
abc();
}
o/p : Hello abc
void tex(long int no)
{
switch(no)
{
case 1 : printf (“one”);
break;
case 2 : printf (“two”);
break;
case 3 : printf (“three”);
break;
case 4 : printf (“four”);
break;
case 5 : printf (“five”);
break;
case 6 : printf (“six”);
break;
case 7 : printf (“seven”);
break;
case 8 : printf (“eight”);
break;
case 9 : printf (“nine”);
break;
case 10 : printf (“ten”);
break;
case 11 : printf (“eleven”);
break;
case 12 : printf (“twelve”);
break;
case 13 : printf (“thirteen”);
break;
case 14 : printf (“fourteen”);
break;
case 15 : printf (“fifteen”);
break;
case 16 : printf (“sixteen”);
break;
case 17 : printf (“seventeen”);
break;
case 18 : printf (“eighteen”);
break;
case 19 : printf (“nineteen”);
break;
case 20 : printf (“twenty”);
break;
case 30 : printf (“thirty”);
break;
case 40 : printf (“forty”);
break;
case 50 : printf (“fifty”);
break;
case 60 : printf (“sixty”);
break;
case 70 : printf (“seventy”);
break;
case 80 : printf (“eighty”);
break;
case 90 : printf (“ninety”);
break;
case 100 : printf (“hundred”);
break;
case 1000 : printf (“Thousand”);
break;
case 1000000 : printf (“Lakh”);
break;
case 10000000 : printf (“Crore”);
break;
}// end of switch
} // end of text.
void digittotx(long int n)
{
long int t;
if(n==0)
printf(“Zero”);
if(n>=10000000)
{
t=n/10000000;
if(t<=20)
text(t)
else
text(10000);
text(t%10);
}
text(10000000);
n=n%10000000;
}
if(n>=1-----)
{
t=n/100000;
if(t<=20)
{
text(t);
else
{
text(t/10*10);
text(t%10);
}
text(100000);
}
if(n>=1000)
{
t=n/1000;
if(t<=20)
text(t);
else
{
text(t/10*10);
text(t%10);
}
text(1000);
n=n%1000;
}
if(n>=100)
{
t=n/100;
text(t);
text(100);
n=n%100;
}
if(n<=20)
text(n);
else
{
text(n/10*10);
text(n%10);
}
void currency (long double rps)
{
long int r,p;
r=(long int)rps;
digittotxt(r);
printf(“Rupees“);
p=(rps-r)*100;
digittotxt(p);
printf(“paise”);
}
void main()
{
long double n;
clrscr();
printf(“Enter amount:”);
scanf(“%LF”,&n);
currency(n);
getch();
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.