Code.GeekInterview.com
  I am new, Sign me up!
 
Code Samples C++
 

Function returning pointers


Code ResourceAuthor: Subashini  

Difficulty Level:

Published: 7th Nov 2006   Read: 2658 times  

Filed in: C++
Add Comment


 


Examples for differentiating function pointers and function returning pointers.

 


Sample Code
  1.  
  2. #include<iostream>
  3. using namespace std;
  4. main()
  5. {
  6.         int * add(int,int);
  7.         int *ptr;
  8.         int x,y;
  9.         cin>>x>>y;
  10.         ptr=add(x,y);//address of the result variable is assigned to ptr
  11.         cout<<"result is"<<*ptr;       
  12. }
  13. int *add(int a,int b)
  14. {
  15. int c=a+b;
  16. return(&c);
  17. }
  18.  
  19. #include<iostream>
  20. using namespace std;
  21. main()
  22. {
  23. int add(int,int);
  24. int (*ptr)(int,int);//declaring function pointer
  25. int x,y,result;
  26. cin>>x>>y;
  27. ptr=add  //address of the function is assinged to ptr
  28. result=(*ptr)(x,y);
  29. }
  30.  
Copyright GeekInterview.com


Next Article: Play Music and Tunes - Music Mantra


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Comment


Members Please Login

Name:  Email: (Optional. Used for Notification)

Title:
 
Comment:
Validation Code: <=>  (Enter this code in text box)





Popular Coders

# Coder NameHits
1. Priya11477
2. bipin_vaylu5094
3. chowsys5025
4. raghu.mohindru4436
5. venki_madesh3293
6. vimal.fire3011
7. Subashini2659
8. prabha2485
9. vipin gupta2079
10. Mehedi Shams Rony1833

Active Coders

Refined Tags

 

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape