declaration

- Default value of variables at the time of declaration -

孤人 提交于 2019-12-05 14:39:18
I was wondering what were the default values of variables before I initialized them... For example, if I do : //myClass.h BOOL myBOOL; // default value ? NSArray *myArray; // default value ? NSUInteger myInteger; // default value ? Some more examples here : //myClass.m // myArray is not initialized, only declared in .h file if ([myArray count] == 0) { // TRUE or FALSE ? // do whatever } More generally, what is returned when I do : [myObjectOnlyDeclaredAndNotInitialized myCustomFunction]; Thank you for your answers. Gotye. The answer is that it depends on the scope in which the variable is

type of int * (*) (int * , int * (*)())

a 夏天 提交于 2019-12-05 10:30:32
int * (*) (int * , int * (*)()) I'd like to know what type is it ? , can someone give an example of a declaration using this type. any help would be great. thanks. It is a pointer to function that returns int* and accepts int* and pointer to function that returns int* (and accepts undefined number of parameters; see comments). Some example (does not look very nice, it is just constructed to contain the mentioned declaration): #include <stdio.h> static int a = 10; int* f1() { return &a; } static int b; int* f2(int *j, int*(*f)()) { b = *j + *f(); // this is just for demonstrational purpose,

Is long long a type in C?

僤鯓⒐⒋嵵緔 提交于 2019-12-05 10:29:16
问题 I know the title seems quite stupid, but I think it's worth asking. Take this declaration(or definition, maybe) for example: _Thread_local long volatile static int _Atomic const long unsigned x = 10; I used to consider long long as a type, but if it's a type name, how can so many qualifiers be inserted into it? So I consulted N1570 with this question, only to be more confused. It mentions some terms such as " type-specifier " and " type-qualifier ", and I can't find long long in "type

How can I make sense of this C type declaration?

爷,独闯天下 提交于 2019-12-05 10:13:05
double (*bar(int, double(*)(double,double[])))(double); While reviewing a lecture slide, I found an exercise left to the student: In plain English, what is the type of bar in this C declaration? Please help walk me through this. I don't even know where to begin, except that something is ultimately returning a double. This answer is brought to you by the ability to use the Spiral Rule . Being able to understand a complex expression by starting at the unknown element and reading around it (resolving things in the parenthesis first). A very useful skill when reading code. bar - bar bar() - is a

Creating an unordered map of <char, int> in java

梦想的初衷 提交于 2019-12-05 10:03:38
So I need to have a some sort of multiset of characters, where adding a duplicate character increases the cardinality by 1, and the multiplicity of characters should not drastically increase the memory that the object takes up. This will be implemented with some sort of map where characters are keys, that hold a value representing the number of that character is represented in the set. However, I'm struggling to figure out which collection would be best for this (I was looking at hashmap) and how to declare this data type. I was doing something like this Map m = new HashMap(char, int); But the

Declaring a variable inside an `if` statement in Java that is a different type depending on the conditional

倾然丶 夕夏残阳落幕 提交于 2019-12-05 09:12:51
I know, I know, there's a ton of simple answers that cover most cases for how to avoid this. In my case, I want to use user-input info to create CPU players in a game. If the user chooses easy mode, then I want to declare and instantiate an instance of the EasyPlayer class. Otherwise, I want to declare and instantiate an instance of the HardPlayer class. Either way, the specific name of the variable needs to be "cpu" and the rest of the code operates on "cpu" indiscriminately. That is, all the differences in how these operate are built into their different classes, which subclass the CpuPlayer

Does T D[N] always declare an object of array type?

走远了吗. 提交于 2019-12-05 08:22:11
I'm confused about [dcl.array]/1 : In a declaration T D where D has the form D1 [ constant-expression opt ] attribute-specifier-seq opt and the type of the identifier in the declaration T D1 is “ derived-declarator-type-list T”, then the type of the identifier of D is an array type; ... Consider the declaration: int (*p)[42]; This declaration satisfies the grammar described above (and does not satisfy the grammar described in previous paragraphs), so this paragraph should apply, thus we conclude that the type of p is an array type. However, we know that the type of p is pointer to array of 42

C++ - Function declarations inside function scopes?

*爱你&永不变心* 提交于 2019-12-05 06:05:23
I was going through C++11 standard draft a while ago and came across this one (in §8.3.6, p. 204): void g(int = 0, ...); // OK, ellipsis is not a parameter so it can follow // a parameter with a default argument void f(int, int); void f(int, int = 7); void h() { f(3); // OK, calls f(3, 7) void f(int = 1, int); // error: does not use default // from surrounding scope } void m() { void f(int, int); // has no defaults f(4); // error: wrong number of arguments void f(int, int = 5); // OK f(4); // OK, calls f(4, 5); void f(int, int = 5); // error: cannot redefine, even to // same value } void n() {

C++ Order of Declaration (in Multi-variable Declaration Line)

断了今生、忘了曾经 提交于 2019-12-05 06:03:38
I use the following in my C++ code: int a = 0, b = a; I would like to know if this behaviour is reliable and well defined (left to right order of name declaration) and that my code will not break with other compilers with an undeclared name error. If not reliable, I would break the statement: int a = 0; int b = a; Thank you. I believe the answer is no. It is subject to core active issue 1342 which says: It is not clear what, if anything, in the existing specification requires that the initialization of multiple init-declarators within a single declaration be performed in declaration order. We

Does redeclaring variables in C++ cost anything?

房东的猫 提交于 2019-12-05 03:10:30
For readability, I think the first code block below is better. But is the second code block faster? First Block: for (int i = 0; i < 5000; i++){ int number = rand() % 10000 + 1; string fizzBuzz = GetStringFromFizzBuzzLogic(number); } Second Block: int number; string fizzBuzz; for (int i = 0; i < 5000; i++){ number = rand() % 10000 + 1; fizzBuzz = GetStringFromFizzBuzzLogic(number); } Does redeclaring variables in C++ cost anything? I benchmarked this particular code, and even WITHOUT optimisation, it came to almost the same runtime for both variants. And as soon as the lowest level of