Monday, July 27, 2009

C++ Please Help?

Which of the following are illegal identifier names, and why?





a) hello


b) int


c) good-bye


d) why_dont_you_continue


e) 1outOfFive


f) payRate


g) x


h) gr8


i) hi!

C++ Please Help?
I know that b is illegal, it's a reserved name for defining a variable type.





c, d, and i will probably be, as they have illegal characters (-, _ and !)


e maybe (I'm not sure) because it starts with a number.
Reply:b) coz' 'int' is a keyword


c) '-' cant be used in identifier


e) can't start identifier with a number


i) can't use '!' in identifier





other all are valid
Reply:b. int, because 'int' is the type's name, compiler knowing 'int' as a type.





c. good-bye, you cannot use '-' as a identifier name because compiler know it as a numeric operator





e.1outOfFive, you cannot use numeric in the front of identifier name


No comments:

Post a Comment