Posts by Maniero • 444,682 points
6,921 posts
-
3
votes2
answers59
viewsA: Program prints the next letter of the alphabet instead of the next char on the pointer
There are two errors in this code. One of it is that it did not allocate memory to put the content, so it will access garbage in memory. And the other is that is not accessing the content pointed by…
-
5
votes2
answers224
viewsA: What is the underscore ( _ ) "inside" of a Javascript number?
It is something new in JS and should be part of ES2021 already being supported by some Engines. See the numerical separator proposal (Numeric separator). It is a way to give more readability to…
-
2
votes2
answers60
viewsA: Access syntax for data pointer member to class pointer
The operator ptrx->value it’s actually the same as (*ptrx).value, I’ll even put it in the code below. So to access a pointer you must dereference it this way, the arrow is only one facility, so…
-
3
votes2
answers137
viewsA: Function returning another function
Okay, confusion is with unified syntax. A lot of people don’t really understand the syntax of the language, whatever it is. It is important to understand everything that is happening and to know…
-
5
votes2
answers103
viewsA: Memory organization when there is inheritance
There is the object and there is the variable. There are types that are by value and types that are by reference. In the types by value the object is placed at the location of the variable, and the…
-
1
votes1
answer73
viewsA: Error pointer -Wint-Conversion ?? Int to int *
The formatter for a pointer is the p and not the x: #include <stdio.h> int main() { int b = 5; int *a = &b; printf("%p\n", a); printf("%d\n", *a); printf("%d", b); } Behold working in the…
-
6
votes3
answers279
viewsA: Is there any way to replace these ifs?
I couldn’t see a pattern so you have to handle it individually. If you have a pattern the question is all wrong. What you can do is create a loop and use a table with the minimum and maximum values,…
-
2
votes1
answer56
viewsA: How to reduce the size of this function that contains multiple if?
The two main conditions are almost identical, only one subexpression is different and what it performs when it enters each is identical, so it really doesn’t make sense to have two conditions. The…
-
2
votes1
answer51
viewsA: Explain to a beginner the query "if(! found)" in the code
First of all, that’s not a query. Second, this code is inefficient, if it thought it should stop searching, and done efficiently and organized, so the search done in a separate function, this…
-
3
votes1
answer59
viewsA: Error handling is not occurring
You have to put all the code you want to be dealt with inside the try, what is outside does not have this "protection" and breaks the application. System.out.println("NOME DO PRODUTO: ");…
-
1
votes2
answers64
viewsA: Increment does not work as expected
First, you must read What is a programming language, IDE and compiler?. If you think you should give another value you should justify it. Programming is justification, otherwise it turns to…
-
6
votes1
answer91
viewsA: What kind of data do you use to store the date of death in a register (Datetime or string)?
Use DateTime? (cancellable type) which permits a null value and so may indicate that that date does not yet exist. Obviously you need to treat properly to not generate errors, but since C# 8 this…
-
1
votes1
answer54
viewsA: Function does not respond correctly
I couldn’t even compile this code because I use a modern compiler configured to give more quality to the code. When I change to compile there is no error, it was like this: #include <stdio.h>…
-
2
votes4
answers142
viewsA: Variable value changes in main function
You’ve declared a global variable, which means out of function, it’s valid for every application, so it’s accessed everywhere. This is not appropriate, it only works well in exercises and should not…
-
6
votes3
answers142
viewsA: Multiple cases on switch with C# 8
The first question on the subject we need to understand is about the syntax of the two constructions. Although they both use the same keyword they are completely different. They took the name to not…
-
2
votes1
answer59
viewsA: Range of values to compare
Test which is easier first, which is unique value, so do this with 1 and 20, then what’s within that range is what’s left, you don’t need to test explicitly, it’s the exception, so it already falls…
-
4
votes2
answers144
viewsA: How does changing the prototype of the String.prototype.toString() method affect this code in Javascript?
Every object can be converted to a textual representation of it. This is done with the function toString(). All types have this, without exception. You may be thinking, but a guy String, is already…
-
2
votes1
answer56
viewsA: What’s the difference in using $_POST['field'] and filter_input(INPUNT_POST,'field')?
Essentially nothing different at all. If you use some filter specification in the function, then it can be different, because a filter will be used and some data will be cleaned within the…
-
3
votes1
answer118
viewsA: Number of Columns X performance in tables
The number of columns does not affect performance by itself. Of course, more data there is a higher cost, but it’s not even proportional, it’s amortized, so the more data you’re dealing with, the…
-
1
votes1
answer69
viewsA: Types like list and str are all primitive types?
By a definition are yes: What is considered primitive in a programming language?, but on the other hand. I’m not sure how they made it official, I think they do, but a lot of the Python…
-
4
votes1
answer58
viewsA: Why does a function accept a reference instead of returning a value?
General reasons: it is more interesting to change an existing storage location than to create a new one, the traditional return performs a copy you need to return more than one value, which is…
-
1
votes1
answer59
viewsA: Math.round() shows the 1675 result, but I wanted it to round to 1700
Since apparently you want to round 2 digits in the whole part then you have to make these digits go to decimals, dividing by 100 and then going back to normal by multiplying by 100, that is, pure…
-
6
votes1
answer51
viewsA: What is the difference between the pre-processor directive and the if statement?
The #if is a conditional that occurs in a phase prior to the compilation, is as if it were another language, the preprocessor understand these commands and generates a different text according to…
-
1
votes1
answer90
viewsA: The loop of choice must end or continue in a menu
I think you want this: int main() { while (1) { char str; cout << "selecione a opcao do objeto 1:"; cin >> ob1; cout << "selecione a opcao do objeto 2:"; cin >> ob2; int apc…
-
4
votes1
answer157
viewsA: What is the difference between string find and index methods in Python?
They serve the same purpose, the difference is in semantics when an error occurs by not finding what you were looking for. The find() returns position -1, so after searching you should test if the…
-
1
votes1
answer47
viewsA: Why is the while condition not an infinite loop?
Javascript is a weak and dynamic typing language. This means that it makes value coercion whenever it is necessary to give a valid result. That’s what gives the language a bad name, if it didn’t…
-
3
votes1
answer54
viewsA: Is it possible to inherit a limited set of methods from a super class in Python?
No, that doesn’t make sense. When you inherit something you are saying that you want what exists. If you don’t want it then don’t inherit it. Inheritance makes you take over all existing contracts…
-
13
votes1
answer451
viewsA: What is Std in C++?
It is a namespace for identifiers. You can create yours, any library can have one or more namespaces, which is nevertheless an identifier that gives a surname to other names. You can see more in…
-
4
votes1
answer102
viewsA: What are the differences between Decorators and Attributes?
Certain terms may be used in slightly different contexts and may have large or small differences in interpretation. About PHP I replied What are attributes in PHP?…
-
1
votes1
answer56
viewsA: What is the purpose of the symbol "&" in the declaration of an object?
This symbol indicates that you are creating a reference instead of a pointer, but it works analogously (not equally). It is part of the type and not the variable, much less the object itself,…
-
3
votes1
answer78
viewsA: Post-increment, pre-increment and its precedence
The first case is a little more complicated because we are not seeing the value of `x , I can infer that it is 3. Then it makes a preincrement and the value of x turns 4. Then he does a…
-
4
votes1
answer68
viewsA: Why does my function only return "even"?
Because that’s what you had done. One return serves to terminate the function, if you did not want it to be closed do not put a return. Maybe I wanted to do this: function parimp(n) { for (var i =…
-
9
votes2
answers289
viewsA: When to use record or class on C#?
TL; DR The main reason to adopt this mechanism is to have a simple data structure that does not adopt the common style in object orientation, that is, there is a preference for functional style. The…
-
3
votes2
answers83
viewsA: Objects eligible for the AG
In 7: Rabbit four = one is assigning the variable value one for the variable four. And what is the value of the variable one at that time? Just look at the previous line that just assigned a value…
-
8
votes1
answer132
viewsA: What are algebraic data types (algebraic data types or Adts)?
Everything in computing has something to do with mathematics, computing is mathematics, not a different invention. Computations are abstractions that we use to express and solve problems, like…
-
2
votes1
answer112
viewsA: How NOT to round up figures?
At least one of the division numbers must be of the type float and is using integer, then the split is done as integer and then the entire result is saved in a variable of type float. Use the suffix…
-
4
votes1
answer425
viewsA: How does the new Java operator work?
Well, that code could be posted completely to give you a better idea of what you’re doing, but you can understand even with that part. This is a code that doesn’t make much sense under normal…
-
4
votes2
answers83
viewsA: Function that creates list inside list
Internally you need to create the internal lists, so at each step you create a different list, so initialize the empty list and at the end of the internal loop add that list to the external list.…
-
1
votes1
answer88
viewsA: error: EOF when Reading a line
It makes no sense to ask the number of students, you already know with the list being sent, just ask the size of the list to use with the function len(). Even asking the user to type manually, if…
-
8
votes2
answers469
viewsA: What are the logical assignment operators ||=, &&= and ??= in Javascript?
This is the operator composed of OR. That is, it is the || which already knows and works exactly the same, but it does an extra operation, it stores the result in the variable itself used, so it is…
-
9
votes1
answer141
viewsA: What are the differences between "String" and "str" in Rust?
What are the differences between them? str is the type to store texts in a more crude way. Remember a little the array of char C, because he’s a array of bytes (a character can be formed by more…
-
1
votes1
answer40
viewsA: You need to indicate how many times the highest number has been read, but you’re not counting that
Unless you have something that is not in the question, the invalid number does not make sense. Why would the smaller number be invalid? It can happen invalidity of the number and it would be nice to…
-
1
votes1
answer48
viewsA: How to know how many times the highest value was read (without list)?
I took the check if it’s negative, because it either does it right or it doesn’t, and the statement posted in the question doesn’t talk about it and that part has nothing to do with reported…
-
2
votes1
answer61
viewsA: Can application with separate frontend be considered monolithic?
It depends on the context that is using the term. It is used in different ways. I’m not going to talk about all contexts because some would make no sense. Executable distribution Within the original…
-
4
votes1
answer177
viewsA: Weighted average with final examination
The first thing I want to say is that people are learning to ask for data that needs to be entered in a specific way and that is a plague. It is already complicated to type right more freely, having…
-
12
votes3
answers229
viewsA: Has Javascript changed its rules about what is false or true?
Rules of programming languages can not change, the whole world depends on them stable, would break everything that people did. Well, in fact they even change when there was a serious error in the…
-
1
votes1
answer33
viewsA: Program that receives a series of notes needs to disregard an invalid entry
Missed not doing the assignment if the validation fails, so I put a continue. And missed to turn the counter back if the item is not inserted, to keep the timing. Missed validate when a entered…
-
4
votes4
answers91
viewsA: How to transform a "for" repeat code into "while" in Javascript?
A for consists of 3 blocks: an initialization, a condition indicating when to end loop repetition and a processing that must happen every time a repetition step ends. The first is quiet playing…
-
9
votes2
answers200
viewsA: What are attributes in PHP? (Annotations/Attributes/Decorators)
They’re used as commentary because the language doesn’t officially support it, so you put it as a text that would be discarded in the code, but some tool reads that code and knows that it needs a…
-
4
votes2
answers1473
viewsA: What is the difference between % and % in C?
The symbol % is used in data input and output functions such as printf() and scanf(). When using this symbol indicates that what comes next is something special that has a meaning of how the data…