ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
class foo {
public:
static int func(const char*& p) const;
};

This is illegal, why?
 Question Submitted By :: Praveen
I also faced this Question!!     Rank Answer Posted By  
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 1
the 2nd const used in the example is invalid because it can 
be used only with member functions which have a hidden 
argument called this. The 2nd const would be applied to 
this.
The funct is static member function so it hasn't any this 
pointer.

Actually it is not obvious what is exactly inccorect.
We can remove static keyword, then we get syntactically 
correct class definition, or we can remove 2nd const and 
again the class can be considered valid.
 
Is This Answer Correct ?    1 Yes 0 No
Rafal Dzbek
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 2
this is illegal because
 
->here the class name is foo
->but,func is declared
->const is declared at outside
 
Is This Answer Correct ?    0 Yes 3 No
Kalpana.y
 
 
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 3
static functions can access static data only
Thus this is illegal
 
Is This Answer Correct ?    1 Yes 1 No
Revathy
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 4
There is nothing to do with class members here, we don't 
see any. The function takes a constant pointer as a 
parameter, when it is constant it cannot be changed 
(although technically we can change by casting), then you 
cannot use reference (&).

But who knows, compilers may accept, I haven't tested.
 
Is This Answer Correct ?    1 Yes 1 No
John Gummadi
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 5
This code is obviously wrong, and here is why :
declaring a method to be const, means : 
this method cannot CHANGE values of any member variables,
but while the method already is static, it has no means of
changing values of member variables, because simply - it
cannot see them (its belongs to a CLASS, not any specific
OBJECT).
 
Is This Answer Correct ?    2 Yes 0 No
Jaroosh
 
  Re: class foo { public: static int func(const char*& p) const; }; This is illegal, why?
Answer
# 6
A member function can be declard as Const by considering 
the fact that they contain a hidden "this pointer" to be a 
pointer to a const object. However Static methods do not 
have the "this pointer", and hence can't be const or 
virtual. 

Hence it is illegal to declare a static function as const.

The C++ language standard stipulates at section 9.4.1 
that "[...] A static
member function shall not be declared const
 
Is This Answer Correct ?    2 Yes 0 No
Abdur Rab
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is the output of below pgm? void main() { int i=0; if(i) printf("pass"); else printf("fail"); }  3
the number 138 is called well ordered number because the three digits in the number (1,3,8) increase from left to right (1<3<8). the number 365 is not well ordered coz 6 is larger than 5. write a program that wull find and display all possible three digit well ordered numbers. sample: 123,124,125,126,127,128,129,134 ,135,136,137,138,139,145,146,147 148 149,156.......789  3
Binary tree traversing Qualcomm1
why you will give me a job in TCS. TCS5
How to convert a binary number to Hexa decimal number?? (Note:Do not convert it into binary and to Hexadecimal) Subex1
What character terminates all strings composed of character arrays? 1) 0 2) . 3) END  3
what is the difference between. system call and library function? CDAC2
what is the difference between strcpy() and memcpy() function?  1
how we can make 3d venturing graphics on outer interface Microsoft1
Write a program to generate prime factors of a given integer?  3
f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output? Hughes6
You are given a string which contains some special characters. You also have set of special characters. You are given other string (call it as pattern string). Your job is to write a program to replace each special characters in given string by pattern string. You are not allowed to create new resulting string. You need to allocate some new memory to given existing string but constraint is you can only allocate memory one time. Allocate memory exactly what you need not more not less. Microsoft2
which one is highest Priority in c? a)=,b)+,c)++,d)==  3
plz answer.. a program that takes a string e.g. "345" and returns integer 345  3
Write a program to print this triangle: * ** * **** * ****** * ******** * ********** Don't use printf statements;use two nested loops instead. you will have to use braces around the body of the outer loop if it contains multiple statements.  2
Write a program that takes three variables(a,b,c) in as separate parameters and rotates the values stored so that value a goes to b,b,to c and c to a  3
How does C++ help with the tradeoff of safety vs. usability?  1
without a terminator how can we print a message in a printf () function. NIIT5
write an algorithm which can find the largest number among the given list using binary search ............... this was asked in the interview Satyam2
how memory store byte Huawei3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com