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?
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?
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.
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?
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);