Different ways of declaring a function in C++ [duplicate] - c++

This question already has answers here:
How does this template magic determine array parameter size?
(3 answers)
Can someone explain this template code that gives me the size of an array? [duplicate]
(4 answers)
How does this "size of array" template function work? [duplicate]
(1 answer)
Closed 2 years ago.
I have come across the following code snippet in C++ and I have no idea what it means;
#include <iostream>
char (&some_function(int (&some_input)));
int main ()
{
// main code here
return 0;
}
How is some_function a function? what kind of syntax is this? where is the body?
I'm sure this is only a C++ syntax as it doesn't compile in C.
Edit:
Actual code with above style:
template <typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))

Related

What does (void) inside of a function does? [duplicate]

This question already has answers here:
Why cast unused return values to void?
(10 answers)
What does casting to `void` really do? [duplicate]
(4 answers)
Closed 5 months ago.
I was working and suddenly I faced a function like that:
void func(SomeStruct *parameter) { (void)parameter; }
I could not wrap my head on what it does.
I mean, there is a function func which the only thing it does is (void)parameter; but I can't get what (void)parameter; is doing int this example.
Would someone mind to explain me, please?

C++ array length function give me a different result than main function [duplicate]

This question already has answers here:
size of array passed to C++ function? [duplicate]
(7 answers)
determine size of array if passed to function
(10 answers)
Sizeof in function [duplicate]
(1 answer)
Closed 6 months ago.
#include<iostream>
#include <string>
using namespace std;
void show_length(int array1[]){
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside function = "<<length<<"\n";
}
int main(){
int array1[6]={3,6,4,2,1,4};
int length=sizeof(array1)/sizeof(array1[0]);
cout<<"Length inside main = "<<length<<"\n";
show_length(array1);
system("pause");
}
i recive 6 as an answer in the main (which is the right answer) but 2 in the separate function, why this happens?

How i can get variable name in c++ without define [duplicate]

This question already has answers here:
converting a variable name to a string in C++
(8 answers)
Closed 2 years ago.
I'm looking for a function that returns a variable name
Theoretical example
template <typename Type>
std::string GetVarName(Type Var)
{
//Get Name
return Variable_name;
}
You could try to stringify the variable using the preprocessor. In the posted link by Schultke there are some examples using macro in order to achieve that.

3d std::array in c++ [duplicate]

This question already has answers here:
C++11: Correct std::array initialization?
(5 answers)
Why can't simple initialize (with braces) 2D std::array? [duplicate]
(1 answer)
Closed 5 years ago.
I am early in c++. I want to define an 3d std::array in c++. when i define bellow array:
std::array<std::array<std::array<double,3>,4>, 4> DownSide = {
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}},
{{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35},{0,0.51,0.35}}
};
I see this error:
error: too many initializers for ‘std::array<std::array<std::array<double, 3ul>, 4ul>, 4ul>’
};
I googled this error find i mistak in numer brackets, but i dont know and find how must i write them.
How must i do?

How to use array as input for a function in c++ [duplicate]

This question already has answers here:
How do I use arrays in C++?
(5 answers)
Closed 10 years ago.
In C++, is it possible to give array as input to a function.
Most likely you can do this all with vectors.
#include <vector>
std::vector<int> function_name(const std::vector<int>& A, const std::vector<int>& B);