Lost Password?

  #1 (permalink)  
Old 03-19-2008, 12:52 AM
Chinmoy's Avatar   
Chinmoy Chinmoy is offline
Programming Professional
 
Join Date: Feb 2008
Location: where heaven meets earth
Posts: 301
Rep Power: 5
Chinmoy has a spectacular aura aboutChinmoy has a spectacular aura about
Default function pointer

Function Pointers are pointers, i.e. variables, which point to the address of a function. Thus they exhibit polymorphism by call by different methods. Function pointers is an exclusive propery of the c language and should be used wisely as functions are always more powerful and fact in execution as compared to function pointers.

Consider the following example.

Code:
#include<stdio.h>
#include<conio.h>

void new_(int);
void old(int);

void main(void)
{
	  void (*funcpoint)(int);
	  int number;
	  clrscr();
	  printf("Enter a number");
	  scanf("%d", &number);
	  funcpoint = (number > 5) ? old : new_;
	  funcpoint(number);
	  getch();
}

void new_(int n)
{
	  printf("The number %d, is less or equal to 5.\n", n);
}
void old(int m)
{
	  printf("The number %d, is more than 5.\n", m);
}
The function pointer *funcpoint is declared here as void (*funcpoint)(int), which specifies both the return type (void) and the types of arguments (int) of the function. We then assign the pointer to a particular function. Now we can call the function normally. This gives a double nature to teh function.
Attached Thumbnails
To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.
__________________
God is real... unless declared an integer
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
server client application - (i really need your help) sarahnetworking C and C++ 5 03-04-2008 10:47 AM
SecurityAudit vinay Visual Basic Programming 27 01-07-2008 12:14 PM
multi-pass preprocessing kenna C and C++ 11 08-14-2007 10:45 AM
Reg Fucntion pointers sowmi C and C++ 9 07-29-2007 03:29 AM


All times are GMT -5. The time now is 06:15 PM.

Contest Stats

dargueta ........ 128.00000
John ........ 127.00000
Xav ........ 107.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

Ads