GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 178 of 203    Print  
Legal Function Naming
Which of the following function name is legal in C++?
A. $_foo()
B. !_foo()
C. 1_foo()
D. -_foo()
E. #_foo()



  
Total Answers and Comments: 3 Last Update: February 16, 2009     Asked by: prettyfox 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: OSaienni
 

A is the only one that will work.

The reason are :

!, - are operators,

# is the preprocessor operator.
     #define, #pragma, also use #9 -> stringify value to char.


1 - numeric value (can be used at end of function / method)

$ isn't used in C++ (I may be wrong here but I've never used $) - So legal naming as its not a number/operator



Above answer was rated as good by the following members:
santhosh.kanchanapally, yzesong
September 10, 2008 09:13:21   #1  
OSaienni Member Since: September 2008   Contribution: 7    

RE: Legal Function Naming

A is the only one that will work.

The reason are :

! - are operators

# is the preprocessor operator.
#define #pragma also use #9 -> stringify value to char.


1 - numeric value (can be used at end of function / method)

$ isn't used in C++ (I may be wrong here but I've never used $) - So legal naming as its not a number/operator


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
December 07, 2008 12:33:54   #2  
burraganesh Member Since: December 2008   Contribution: 20    

RE: Legal Function Naming
$_foo()
$ symbol is used by compiler in a process called "name mangling" where each functions name and signature are preceded by $.
Thus $ is a valid symbol that a compiler can understand

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 16, 2009 01:29:00   #3  
santhosh.kanchanapally Member Since: April 2008   Contribution: 10    

RE: Legal Function Naming
void $_foo();

Can be used as function name

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

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

Page copy protected against web site content infringement by Copyscape