Posts by Maniero • 444,682 points
6,921 posts
-
5
votes1
answer480
viewsA: Difference between Dictionaries and Lists/Arrays?
In general the 3 are used to contain diverse elements (objects) (can be of the same type or not, depends on the language and form of use of them) and the access to the elements are made through an…
-
6
votes1
answer742
viewsA: How does Python manage memory when assigning different types?
Dynamic typing languages usually have only 1 type that is the object. This type has the infrastructure to manage other types of data. I imagine you understand how data is stored in memory, you know…
-
2
votes1
answer193
viewsA: What’s the difference between Dynamic and Object
Object is a type like any other that is used as a basis for the other types and have a few members as you can see in documentation. So it’s mostly used to compose other types or indicate that you…
-
2
votes1
answer136
viewsA: How do closures work on Swift?
In fact we have already explained this in several posts about the closure in itself and the anonymous function that is related and important concept: What is the difference between the functions var…
-
1
votes2
answers78
viewsA: Access vector value by index
What is doing there only those who wrote the code can say. It may have been unintentionally. If it was by wanting the meaning it would be that she wants the next letter of the alphabet, skipping…
-
2
votes1
answer64
viewsA: Variable that has a variable in its name
Ali gets a array. In addition to seeing the link previous would be good to understand well What is a variable?. Then a array being variables within variables, you have to have a way of saying what…
-
1
votes2
answers104
viewsA: Concatenate string and return the number of characters
There are some mistakes there. The most obvious is that you have made a typo in the name of the property that gives the size of the text, the correct is length. Javascript instead of giving error…
-
1
votes1
answer69
viewsA: How to make strftime accept a Std::string?
You’re passing a reference to this function to fill in the data. You’re not passing the dice, because you don’t even have one, so it doesn’t make sense to convert one guy to another, you have to…
-
6
votes1
answer114
viewsA: Is every anonymous function a closure?
No, they’re completely independent mechanisms. Although it is technically possible to have a cloning mechanism in a function that is not anonymous, I only know implementations of closure in…
-
2
votes1
answer41
viewsA: Register state in Calling covention
The question should be the opposite. Why make a push EBP if you’re not gonna touch the register EBP? The instruction push puts the value of the register on the stack to determine when to recover the…
-
3
votes1
answer139
viewsA: In the CPU time equation (Tcpu) what are the number of instructions (IC) and cycles per instruction (CPI)?
The cycle is the basic unit of execution, is the minimum step of execution that occurs and the time between one and the other is defined by the mechanism of clock from the computer, so a 4Ghz…
-
3
votes1
answer55
viewsA: Relationships between classes in the OO
What you call an attribute actually calls a field (I know, everyone learned wrong and teaches wrong). If you have these two related classes you need to have a way to get to each other. At least one…
-
3
votes1
answer75
viewsA: Use of Eval. Is there any alternative in this case?
If I understood anything at all: var funcoes = { sen: Math.sin, cos: Math.cos, e: Math.E, ln: Math.log, } var funcao = "sen"; console.log(funcoes[funcao](30)); I put in the Github for future…
-
5
votes1
answer241
viewsA: Should I ask for the user’s password twice at the time of registration?
Every answer about UX has to start with that blah blah that you have to conduct studies, analyze your audience, etc. Done this and to give a parameter I will resort to UX.SE which is one of the…
-
4
votes2
answers242
viewsA: Object orientation: what defines the identity of an entity?
What defines the identity of an entity? I don’t like the definition of the term given in the context of object orientation, so I’ll just put what’s on Wikipedia not to give a definition of my own:…
-
2
votes2
answers116
views -
1
votes1
answer54
viewsA: Understanding of string delimiter
I will make comments showing what makes each part, I am rewriting parts to be more readable and breaking some to facilitate comments: char *strdelc(char *s, char ch) { int j = 0; //faz a declaração…
-
3
votes2
answers253
viewsA: Is it OK to use a switch inside a for?
Correct is not always easy to say, strictly speaking it is correct because it works and gives the result you want in all situations of this stretch, so no one can say you are wrong. Not the most…
-
4
votes3
answers77
viewsA: How can I access a subclass method through a superclass-like object
Essentially you shouldn’t do that. It’s a pity that in an artificial example it’s even worth doing and seems right. If you want to do it anyway you should perform a cast to make the object type…
-
1
votes1
answer89
views -
5
votes2
answers76
viewsA: Going into if wrong
This syntax does not make sense, it can make the code much simpler and there correct. You can only do one comparison at a time, if you have to compose two comparisons you have to use an operator ||…
-
3
votes1
answer102
viewsA: Should I specify the type of return of a procedure in Python?
Python allows you to use explicit typing. It doesn’t mean that it has become a static typing language, but it helps to make the code more readable and even catch some errors some extra tools. Each…
-
3
votes2
answers571
viewsA: How to handle multiple conditionals (if and if if followed) in Java and how to compress them?
There are 4 different actions, so at least 4 ifs must be used. Each action happens with two different conditions, so there is no reason to have two ifs, just concatenate the two conditions creating…
-
3
votes2
answers200
viewsA: getchar() command used several times
Thus? #include <stdio.h> int main() { char c; printf("Digite um caractere:\n"); char c1 = getchar(); while ((c = getchar()) != '\n' && c != EOF) { } printf("Digite um caractere:\n");…
-
3
votes1
answer160
views -
6
votes1
answer509
viewsA: Polymorphism in Typescript
Cast As far as I know (may have a solution I don’t know on TS) has no good solution, so it works: abstract class Pessoa { id?: number; nome?: string; } class PessoaFisica extends Pessoa { public…
-
6
votes3
answers203
viewsA: Should I always use Try catch to fix mistakes?
There are controversies. It depends on what you want and the style you adopt. The Python community prefers the call EAFP instead of LBYL (reference). Of course you have to analyze each case, but it…
-
1
votes1
answer252
viewsA: C++ free(): invalid aborted when trying to create a function
You’re not returning anything, so there’s no point in having some kind of return there. If you were to return, which is not necessary in the code presented, then you would have to have a return in…
-
4
votes2
answers108
viewsA: Why don’t files show your bits?
I open a file .exe with the notepad and see instead of 100101 I see a lot of strange characters why that? What characters are those? Because the notepad wanted to show like this. What you see is…
-
4
votes2
answers70
viewsA: Pointer pointing to another pointer, how to use the free() correctly?
Let’s look at the code: #include <stdio.h> #include <stdlib.h> int main(void) { int *ponteiro1 = malloc(sizeof(int)); *ponteiro1 = 5; int *ponteiro2 = ponteiro1; printf("%p == %p, %d ==…
-
3
votes1
answer65
viewsA: How is it decided on the writing patterns on the computer?
It is not simple to say whether it is in hardware or operating system, because it happens in both. This is defined in several ways. Don’t think that only exists in one place and everything…
-
5
votes2
answers773
viewsA: How to subtract several elements from a list?
You’re taking the whole list, so the first subtraction is the element you’ve already taken, the first step of the loop will reset the value because a number minus it is always zero, then the account…
-
3
votes1
answer44
viewsA: Heap things on a function x DRY
It’s not about OOP, it’s about modularization. OOP can be a technique to be used for this. Breaking something in various methods is not even something of OOP even, OOP can facilitate because you…
-
1
votes1
answer42
viewsA: How to create a parameterized variable?
What you want to use is array. But you should be careful because it’s easy to mess with it in C. You have to make sure you store the right amount of data. If you try to carve something out of it, it…
-
1
votes2
answers146
viewsA: How to give an UPDATE by swapping for ?
The backslash has special significance in strings. It indicates that the next character is special and should not be treated as a normal character. At the same time it takes some special character…
-
3
votes1
answer58
viewsA: How is a executable erased from memory?
It is not erased. Simple as that. And this can be a security problem if it kept sensitive data in memory. Not that this is any less of a problem while it’s running, but if something happens that you…
-
4
votes2
answers112
viewsA: Generating a txt with random numbers repeats the numbers
This code has some problems. The biggest one is that it is starting the random seed every time it will use so it causes the repetition. You must trigger the seed once and then consume. You only…
-
3
votes1
answer122
views -
3
votes1
answer63
viewsA: What is the code convention name for variables that use _?
It is usually called Snake Case, or snake_case as some prefer. This style states that any space between the words that form a unique identifier is replaced by a undeline, since the identifier cannot…
-
2
votes2
answers286
viewsA: Difference between global and local scope
The question does not speak of specific languages so be careful because this exact definition may vary somewhat from language to language. The general is the same, but the details change. I’ve…
-
8
votes3
answers387
viewsA: Is there more than one way to use "if"?
What is the if The first thing you should understand is that the if is not a function, is a language command (this can be seen more in What are statements and operators? and What is the difference…
-
1
votes1
answer54
viewsA: Payment details of installments of insurance policies
From what I understand you will have two tables (it is possible that you have others, but not for this part of the problem), one with the general details of the payment and the other for the…
-
2
votes2
answers54
viewsA: What does the # operator do before a parameter in the definition of a macro?
He’s a kind of toString() of macro. He takes that content and turns it into a string, so he quotes there on that expression. So let’s say that you call the (macro) function of the question like…
-
1
votes1
answer72
viewsA: How does access to struct by pointer pointer and by a copy of the pointer work?
The difference is on this line: typedef Node *No; When you wear one typedef is saying that you want a name to represent some other existing definition that is placed just before the name. So in this…
-
2
votes1
answer281
viewsA: Limit number of digits in data entry
There’s a conceptual error there. You’re asking for a password, a descriptive information, so it must be a string and not a number. You could even validate to only have numeric digits, but just…
-
5
votes2
answers181
viewsA: Simple ways to break a *while* with a function
It doesn’t seem like a good idea. It seems that the while is part of the function algorithm (it is one that asks for a data validating it) and should not be separated. Even the name of the function…
-
3
votes2
answers164
viewsA: Upcasting and subsequent downcasting allows you to access the attribute of the original type?
Upcasting|, At least in this situation, it is only a reinterpretation made by the compiler, he starts to understand what to access, without moving anything on the object. It is possible to have a…
-
2
votes2
answers161
views -
4
votes6
answers444
viewsA: Counting multiples of an integer is giving very different values than expected
I imagine that’s what you wish: n1 = int(input()) n2 = int(input()) count = 0 for c in range(n1, n2): if c % n1 == 0: count += 1 print('O numero {} tem {} multiplos menores que {}.'.format(n1,…
-
0
votes1
answer48
viewsA: Code does not display result
There is a syntax error there, so the compiler has an error, it doesn’t get stuck. The code has several errors even of interpretation, at least for what it can infer from the messages contained in…