Most voted "function" questions
The function (also called procedure, method, subprogram, or routine) is a portion of code intended to perform a single, specific task.
Learn more…1,309 questions
Sort by count of
-
6
votes2
answers379
viewsIs it bad practice to overwrite declared variables as a function parameter?
I used to get "reassigned" a value of a certain variable that was declared as nome of the function parameter. Example: function format($string) { $string = ltrim(rtrim($string, ']'), '['); // A…
-
6
votes1
answer80
viewsHow long is the data allocated to functions?
In one language, (I don’t know if there’s any difference in others, but you can consider Javascript) when I have this situation: function a() { b(); } function b() { c(); } function c() { d(); }…
-
6
votes3
answers268
viewsHow do Javascript functions behave in relation to the scope?
In Javascript, functions are objects and can be passed as parameters to other functions. But what about when a function with dependencies on an object, such as variables and other functions, is…
-
6
votes1
answer1353
viewsHow to return or extract more than one value from a function?
integerPower( int y ){ int base2; int base3; int base4; int total; base2 = pow( y , 2); base3 = pow( y, 3); base4 = pow( y, 4); When I call this function (I did not type return because that’s the…
-
6
votes2
answers644
viewsArc tangent function in C#
I did the following calculation on the calculator: arctg(50/10) = 78,69° However, when doing in the code, using the function Math.Atan, the result is as follows: Is there any other way to calculate…
-
6
votes1
answer282
viewsShould we disregard the return of functions in C that already receive the desired value by the parameter by reference?
Looking at the documentation of scanf() I saw that it returns a value, but I see the codes using it without using that return. This is right?…
-
6
votes1
answer3403
viewsHow does any and all work in Python?
How the functions work any and all in Python and what are the differences between them? They happen to be functions equivalent to Array.prototype.some and Array.prototype.every javascript?…
-
6
votes2
answers312
viewsWho is who in the use of functions?
I have searched a lot, and has a lot of good content here, which covers this topic, however I still can not understand the functioning. The characters I’m referring to are: Function Parameters…
-
6
votes3
answers8795
viewsHow to round a number to the highest value in Mysql?
I was doing some tests on Mysql and then the need arose to have to round a number to the largest. It would be something like: if($numero == 1.5){ $numero = 2; } Even though I could do it like this,…
-
6
votes1
answer4920
viewsIs there a difference between using "Return" or "Exit()" to terminate the "main()" function?
The function exit() closes the execution of the application immediately. The command return makes you quit the function, but when you’re inside the main() will exit the application, including the…
-
6
votes3
answers185
viewsWhere to place a function "toFixed()` to round up the value?
I would like to round off the final value of my code with the .toFixed() but I don’t know where to put. Here is the code: <script type="text/javascript"> function conversao(fahreinheit) {…
-
6
votes1
answer348
viewsDifference between constructor and function that returns literal object
What is the practical difference between me creating a construction function in this way: function construtora (nome, sobrenome) { this.nome = nome this.sobrenome = sobrenome } Or in this way:…
javascript function characteristic-language objects builderasked 4 years, 6 months ago Gustavo Paiva 173 -
6
votes2
answers155
viewsIs there any way to prevent the use of "new" in a Javascript function?
Assuming the function: function foo() { return 'something'; } It is possible to invoke it (abstract operation [[Call]]): // Invocando `foo`: foo(); In the above example, the string would be returned…
-
5
votes2
answers2276
viewsMethods without parameters and with parameters
Declaration methods without parameters: void exemploDeMetodo(){ int i; } Calling methods without parameters: exemploDeMetodo(); If I want to make a method with parameters it’s like? That’s the way…
-
5
votes2
answers887
viewsCheck if variable has been set
How do I check if a variable has been set? The #ifndef can be used for this? Plainer: #include <iostream> int getNumber() { if (check) { check = false; return 10; } else { bool check = true;…
-
5
votes1
answer31551
viewsPass matrix as function parameter?
I’m studying Dijkstra’s algorithm and I haven’t tried using adjacency lists yet. I knew I could solve the problem with a matrix, but the fact is that I can not receive the matrix in the function. If…
-
5
votes2
answers7137
viewsWhat does KWARGS in Python mean?
I know that, in Python, we can define in a function something similar to what they call "named Parameters", ie, "named parameters". def my_func(**kwargs): pass my_func(nome="Stack Overflow",…
-
5
votes2
answers154
viewsReturn a function
I created a function teste() which must be completed with the While and return the data. Why when I call my function teste() within the function PageLoad_Arquivo() it does not carry? function…
-
5
votes1
answer3721
viewsIs it possible to know the functions of a DLL without having its documentation?
It is possible to discover which functions are available in a DLL without having its documentation in hand so we can use, in Java, for example?
-
5
votes3
answers213
viewsWhy don’t I need to pass parameters to that function?
I would like to know how the function passage works as a parameter in JS, I am starting in the language now and I needed to make a call to EventListenner…
-
5
votes1
answer95
viewsDo static methods equate to functions?
In OOP we have static methods (do not depend on any instance variable). Citing examples: class Somar { public static function soma($a,$b){ return $a+$b; } } echo Somar::soma(20,30); The equivalent…
-
5
votes2
answers859
viewsInvert array (vector) without an external function, 'manually'
Friends, I always invert vectors using an auxiliary in an external function (I think the standard way), however until recently a friend told me that had a way to invert vectors without using an…
-
5
votes1
answer235
viewsBug in code, function repeats calling when opening excel file
Further to this question: /a/112899/13237 Code: Function PrinciQualidade14(LNumber As Integer) As String If LNumber < 15 And LNumber > 0 Then InsertPictureInRange LNumber,…
-
5
votes3
answers134
viewsWhy do libraries use "! function_exists('function')" always when there is a statement of a function?
I’ve used several PHP libraries and realized that they always use the same statement, whenever there is a declaration of a new function. if (! function_exists('funcao')) { function funcao($arg) { }…
-
5
votes1
answer1048
viewsCan I invoke Function on a Trigger?
My Function done on Sql-Server: CREATE FUNCTION dbo.getQuantidade(@idProd char) RETURNS float AS BEGIN DECLARE @QTD float SET @QTD = (SELECT (prod.Quantidade) FROM Produto prod where @id_prod =…
-
5
votes1
answer159
viewsPurpose of lambda syntax in function/method
In some cases a function/method contains only one line in its scope, see the illustrative example: static int Soma(int a, int b) { return a + b; } Meanwhile, to a new feature in C# 6.0 that allows…
c# function lambda-expressions characteristic-language methodasked 8 years, 4 months ago gato 22,329 -
5
votes1
answer476
viewsWhy use pointers as function parameters?
I already have a certain knowledge about pointer, but I wanted to understand why in most cases people use pointers as parameters in functions. Currently I have been studying algorithms through the…
-
5
votes1
answer284
viewsDoubt with Javascript Arrow Function
In the code below, the method showName() naturally return undefined, because it will fetch a name property in the scope where the obj is inserted. My question is, in that case I would necessarily…
-
5
votes3
answers26954
viewsPython maximum and minimum
What is the function I use to find the maximum and minimum values between 2 values in Python? Thank you
-
5
votes0
answers40
viewsWhat is the purpose of using "&" in passing parameters to PHP functions?
Good staff, Following pointer logic I came across the following problem. If you run the function below using "&" the PHP memory consumption goes up, it should not be the other way around since I…
-
5
votes1
answer34
viewsHow can Jquery be both function and object?
I know little about Javascript, and I was trying to understand how Jquery can be a function and an object at the same time. I wondered how it was developed so that it could be called as a function…
-
5
votes1
answer483
viewsHow to correctly divide a number to only one digit in C?
I have the following function : divisibilidade11(int num); And the following variables: : int dividendo; int divisor; When the user enters with the type 11 for the variable divisor the function…
-
5
votes3
answers349
viewsWhat are the advantages of using PHP’s sprintf function?
I can see an advantage in using the function sprintf in place of concatenation: readability. In addition to readability, what are the other advantages of sprintf() in relation to concatenation? Is…
-
5
votes2
answers181
viewsSimple ways to break a *while* with a function
I usually run into this problem: while True: input_chute = int(input("chute: ")) if input_chute == 0: break bla bla bla ... In that example above I break while with a condition and a break, however,…
-
5
votes3
answers464
viewsWhat is a Guard clause?
What is a Guard clause? Possible translations and synonyms: Custody clause Guard status Sentinel clause Prevention clause Protection clause Fuller definition. What are its advantages? The code is…
-
5
votes2
answers238
viewsPython dictionary and functions
I don’t understand why the following code says that it is receiving more than one pro value same parameter. def foo(name, **kwds): return 'name' in kwds foo(1, **{'name' : 2})´ Typeerror: foo() got…
-
5
votes1
answer117
viewsLoop Error in R
I created this loop: library(forecast) a=1 b=60 while(b<=(NROW(tsarroz))){ janela=dput(tsarroz [a:b]) serie=ts(janela,freq=6) HW=HoltWinters(serie) prev=forecast(HW,6)…
-
5
votes2
answers172
viewsWhy don’t I need to declare the parameter in the function?
In the React documentation he brings an example of form, when the input receives some property value onChange is called with the function handleSubmit(event) in that way onChange={this.handleChange}…
-
5
votes1
answer82
viewsR - Function to generate graphs and change axes
I need to display four charts several times in a Rmarkdown report. So I decided to create a function to plot the graphs. It was like this: gera_graficos <- function(base,var1,var2){ hist1 <-…
-
4
votes3
answers157
viewsRefactoring function to collect constants with a certain prefix
I have a function that aims to locate and group in a matrix the constants that are declared corresponding to a certain prefix: Function: function get_constantsByPrefix($prefix) { foreach…
-
4
votes2
answers334
viewsLoop to perform calculation in C Pagerank
Using the starting notes 0.15 for all and then add note as explained in the article http://cmup.fc.up.pt/cmup/mecs/googlePR.pdf If we consider pages 1, 2 and 3 to be: 1: link1 2: link2 3: link3…
-
4
votes3
answers10588
viewsGlobal variable in all functions of the class
Usually when I want to pull a variable that is out of class, I use global $variavel, but wanted this variable to be accessible in all functions of the class, not to be needing to "pull" in all…
-
4
votes2
answers99
viewsPreset in Javascript function parameters
Is it possible to make parameter presets in Javascript functions? Something like: function teste(oi = "ola", type = 1) { To predefine variables if they are not defined?…
-
4
votes3
answers154
viewsOptimization of PHP functions for database querys
I often see different functions in PHP for each query. I wonder if there is any other way to do the following, in a connection with PDO: function get_user_data($table, $columm, $required) { $db =…
-
4
votes2
answers185
viewsExplode() 'manual' in PHP
Just for the challenge and the taste of programming I’m trying to recreate the function explode() in PHP. This is what I have so far: function explode_by_me($divideBy, $str) { $element = "";…
-
4
votes2
answers185
viewsHow to pass an array as argument with the user defining the column number?
I’ll make a simple program just to illustrate my problem. #include<iostream> using namespace std; void recebeValor( int mat[][col]) // me da erro de comp; { mat[0][0] = 2; cout <<…
-
4
votes1
answer397
viewsIn PHP, is there any way to import only one function from a given file?
I see that in Python, we can import only one function from a particular module, without having to load it all. In addition to this being great to avoid function name conflicts. Example: #funcs.py…
-
4
votes1
answer113
viewsUse regression residues to calculate another regression (within the function) in R
I’m using a function to calculate regressions. I need the residues of a specific relation to relate to another variable. However I need the waste to be calculated according to Facet grid. Thus, for…
-
4
votes1
answer2492
viewsRecursive functions in C++: examples
I am starting to learn C++ and I am currently focusing on recursive functions. I’ve seen some interesting examples, like the factorial calculation of a number, but I’d like to see other examples. I…
-
4
votes1
answer3427
viewsStatement const at the end of function in C++ and const before argument in method
I came across this piece of code in a material: class Foo { public: int Bar(int arg1) const //<-- qual função do const aqui? { // código a ser implementado aqui } }; [1] Like the const affects…