New Posts  All Forums:Forum Nav:

C++ identifiers

post #1 of 6
Thread Starter 
This is one of my homework questions.
Code:
Are the following ones valid C++ identifiers, why and why not ? 
2ABC,  E/BC,  case,  _int,   sizeof,  j k,  goto(),  theSecond(), Goto(), return(), 
newamp(), volts$, a2b3,  new.of,  average,  _c3,   a1b2c3d4,  12345,   $total.
These are my answers. I try them, at least the one I am not sure of, in VS 2010 and got my results. However, when I look at the notes that my prof gave us, it said that "only letters, digits, or underscores may follow the initial letter (no blanks allowed)" and that "keywords cannot be used."

Code:
2ABC – This is invalid identifier. First character is a number.
E/BC – This is invalid identifier. There is a slash.
Case – This is valid identifier.
_int – This is valid identifier.
sizeof – This is invalid identifier. sizeof is a keyword
j k – This is invalid identifier.  There is a space.
goto() – This is invalid identifier. goto is a keyword.
theSecond() – This is valid identifier.
Goto() – This is valid identifier.
return() – This is invalid identifier. return is a keyword.
newamp() – This is valid identifier.
volts$ – This is valid identifier.
a2b3 – This is valid identifier.
new.of – This is invalid identifier. new is a keyword.
average – This is valid identifier.
_c3 – This is valid identifier.
a1b2c3d4 – This is valid identifier.
12345 – This is invalid identifier. First character is a number
$total – This is valid identifier.
My questions and the one I am still not sure.
Since C++ is case sensitive, Case and Goto are okay since the first letter is uppercase, but just not a good practice.The one that is the function calls, the one with (), identifier includes function calls, right?? The one with the $, I tried them in VS 2010 and they are okay, didnt give me an error. But as my prof definition as above said, it should be invalid.
If I make any mistake on the other ones, feel free to correct me.
Thanks. +rep if you can help.
post #2 of 6
$ probably has some special meaning, which is why it works anyway.
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
Akiyama Mio
(13 items)
 
  
CPUMotherboardGraphicsRAM
E6420 @ stock, 0.98v Asus P5N-E SLI Gainward GTX 460 1GB @ 800/1600/1900 2x2GB Kingston @ 800MHz 5-5-5-15 2T 
Hard DriveOptical DriveOSMonitor
WD 250GB, 320GB SATA/3, 16MB Cache, Seagate 1TB LG GSA-H62N 18x SATA Ubuntu 9.10 x86 & Win7 x86 Asus VW222U 
KeyboardPowerCase
Logitech Classic Corsair 650HX NZXT Apollo Black 
  hide details  
Reply
post #3 of 6
yes, when () are used you are making a call to a function...it could be a library function or a function created by you. I know the "$" character is important in assembly language...and I know you can create assembly programs in VS. Also assembly language is the foundation for c++ and just about any other language...so there might be some connection there but to be honest I dont think I've ever used "$" in a c++ program so far.
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #4 of 6
I agree with the previous posts, the $ sign is throwing me off, I always thought the only symbol you were suppose to use was the underscore. I haven't used C++ let alone assembly to know what the connection between the 2 is. It looks like the $ is meant for mechanically generated code... according to a post here

Quoting this from here
Quote:
The dollar sign ($) can be used as an embedded character in identifiers. If the dollar sign is used in identifiers, the dollars translator option must be specified. Use of the dollar sign is not portable because the dollar sign is not part of the portable C++ character set. The dollar sign cannot be used as the first character in an identifier; such usage is reserved for the library.

Edited by Chunkylad - 6/10/11 at 9:34am
Project Purity
(18 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 EVGA P55 FTW 200 EVGA GTX 480 Corsair Dominator GT 4Gb x 2 
Hard DriveOptical DriveCoolingCooling
2x500gb Spinpoint F3 (Raid 0)/1tb Spinpoint F3 Asus DRW Heatkiller 3.0 XSPC EX360 
CoolingCoolingOSMonitor
Swiftech MCP655 EK GTX 480 Windows 7 Ultimate 64-bit Samsung UN32C6500 32" LED TV 
KeyboardPowerCaseMouse
Steelseries Merc Stealth Corsair HX1000W Corsair Obsidian 800d Razer Mamba 
Mouse PadAudio
Razer Destructor Asus Xonar DX 
  hide details  
Reply
Project Purity
(18 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 EVGA P55 FTW 200 EVGA GTX 480 Corsair Dominator GT 4Gb x 2 
Hard DriveOptical DriveCoolingCooling
2x500gb Spinpoint F3 (Raid 0)/1tb Spinpoint F3 Asus DRW Heatkiller 3.0 XSPC EX360 
CoolingCoolingOSMonitor
Swiftech MCP655 EK GTX 480 Windows 7 Ultimate 64-bit Samsung UN32C6500 32" LED TV 
KeyboardPowerCaseMouse
Steelseries Merc Stealth Corsair HX1000W Corsair Obsidian 800d Razer Mamba 
Mouse PadAudio
Razer Destructor Asus Xonar DX 
  hide details  
Reply
post #5 of 6
$ is hex number so example when u wanna pre assign value to integer int i $100; that means that integer i is holding a value of 100 in hex. I hope it helps.
post #6 of 6
Quote:
Originally Posted by Skeyo View Post
$ is hex number so example when u wanna pre assign value to integer int i $100; that means that integer i is holding a value of 100 in hex. I hope it helps.
Incorrect. In C++, hexadecimal constants are prefixed by 0x.

Code:
int i = 0x100; // will hold hex 100 == decimal 256
int i = $100; // this will usually give a compiler error citing identifier violation
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
RAID0R
(14 items)
 
  
CPUMotherboardGraphicsRAM
i5 750 4.0GHz MSI P55-GD80 GTX 470 | 8800GT PhysX 2x2GB G.Skill Ripjaws 
Hard DriveOptical DriveCoolingOS
60GB Agility 2|1TB RAID0|1.5TB Pioneer DVR-217D XSPC Raystorm | XSPC RX240 Windows 7 Professional x64 
MonitorKeyboardPowerCase
27" Dell 2709W | 17" Samsung Logitech G15 Corsair HX850 Corsair 650D 
Mouse
Microsoft IntelliMouse 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming