Question

can anyone briefly explain what the meaning of any of these statements are?

1) const char hi [] { 'H', 'E', 'L', 'L', 'O', '\0' }; 2) ifstream fileObjs [3]; 3) long double bigNums [10000] = { 10000 }; 4) char* strRefs [2000];

5) int foo(); 6) double foo(double, double); 7) foo(24); 8) int& foo (int& chat);

Also, what were would I be likely to find statements like 5,6,7,8? Thanks in advance

Was it helpful?

Solution

1) this is a character array called "hi" that is initialized to the string "HELLO\0"

2) this is an array of 3 ifstream objects

3) this is an array of 10000 long doubles, and the first is 10000

4) this is an array of 2000 character pointers

5) this is a declaration of a function named foo with no paramaters, that returns an int.

6) this is a declaration of a function named foo that takes two parameters, both of type double, that returns a double.

7) this is a call to a function names foo

8) this is a declaration of a function named foo that takes a reference to an integer and returns a reference to an integer.

You'd likely find statement five in a file where the function definition is below another function where the statement is used. In this case, the function using the foo would need to know its signature before the compiler could verify it. This is sometimes called forward declaration. Same for 6 & 8

7 would be found in most programs where another function is required to do some work. This is generally used to break up large pieces of code into more managable or reusable chunks.

OTHER TIPS

In order to do anything in C++, you'll need to know what these statements mean. If you are trying to learn the language and actually build or even just hack something, you are better off understanding these core concepts instead of getting quick and dirty answers. Any online reference or book should have chapters on functions and arrays, so perhaps you could start there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top