variable-names

dollar sign in variable name?

女生的网名这么多〃 提交于 2019-11-26 03:59:42
问题 I stumbled on some C++ code like this: int $T$S; First I thought that it was some sort of PHP code or something wrongly pasted in there but it compiles and runs nicely (on MSVC 2008). What kind of characters are valid for variables in C++ and are there any other weird characters you can use? 回答1: The only legal characters according to the standard are alphanumerics and the underscore. The standard does require that just about anything Unicode considers alphabetic is acceptable (but only as

Why can't variable names start with numbers?

此生再无相见时 提交于 2019-11-26 01:36:23
问题 I was working with a new C++ developer a while back when he asked the question: \"Why can\'t variable names start with numbers?\" I couldn\'t come up with an answer except that some numbers can have text in them (123456L, 123456U) and that wouldn\'t be possible if the compilers were thinking everything with some amount of alpha characters was a variable name. Was that the right answer? Are there any more reasons? string 2BeOrNot2Be = \"that is the question\"; // Why won\'t this compile? 回答1:

Create multiple numbered variables based on a int

浪尽此生 提交于 2019-11-25 23:29:07
问题 How would I create a number of NSDictionary variables using an array\'s count? This is basically what I came up with, but I\'m not sure how to make this work with Objective-C syntax. doesntContainAnother is an NSArray . I want the names of the dictionaries to use the current value of loopInt . int *loopInt = 0; while (doesntContainAnother.count <= loopInt) { NSMutableDictionary *[NSString stringWithFormat:@\"loopDictionary%i\", loopInt] = [[[NSMutableDictionary alloc] init] autorelease];

Table name as variable

假装没事ソ 提交于 2019-11-25 22:23:41
问题 I am trying to execute this query: declare @tablename varchar(50) set @tablename = \'test\' select * from @tablename This produces the following error: Msg 1087, Level 16, State 1, Line 5 Must declare the table variable \"@tablename\". What\'s the right way to have table name populated dynamically? 回答1: Table names and column names need to be static, if the query is static. For dynamic table or column names, you should generate the full SQL dynamically, and use sp_executesql to execute it.

Create variables with names from strings

给你一囗甜甜゛ 提交于 2019-11-25 19:44:17
Let's assume that I want to create 10 variables which would look like this: x1 = 1; x2 = 2; x3 = 3; x4 = 4; . . xi = i; This is a simplified version of what I'm intending to do. Basically I just want so save code lines by creating these variables in an automated way. Is there the possibility to construct a variable name in Matlab? The pattern in my example would be ["x", num2str(i)] . But I cant find a way to create a variable with that name. You can do it with eval but you really should not eval(['x', num2str(i), ' = ', num2str(i)]); %//Not recommended Rather use a cell array: x{i} = i I also