Return array in a function

In this case, your array variable arr can actually also be treated as a pointer to the beginning of your array’s block in memory, by an implicit conversion. This syntax that you’re using: Is kind of just syntactic sugar. You could really replace it with this and it would still work: So in the same … Read more

Define a global variable in a JavaScript function

As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable: (Note that that’s only true at global scope. If that code were in a module — <script type=”module”>…</script> — it wouldn’t be at global scope, so that wouldn’t create a global.) Alternatively: In modern environments, you can assign to … Read more

strdup() – what does it do in C?

Exactly what it sounds like, assuming you’re used to the abbreviated way in which C and UNIX assigns words, it duplicates strings 🙂 Keeping in mind it’s actually not part of the ISO C standard itself(a) (it’s a POSIX thing), it’s effectively doing the same as the following code: In other words: It tries to allocate enough memory … Read more

strdup() – what does it do in C?

Exactly what it sounds like, assuming you’re used to the abbreviated way in which C and UNIX assigns words, it duplicates strings 🙂 Keeping in mind it’s actually not part of the ISO C standard itself(a) (it’s a POSIX thing), it’s effectively doing the same as the following code: In other words: It tries to allocate enough memory … Read more

How to send an email with Python?

I recommend that you use the standard packages email and smtplib together to send email. Please look at the following example (reproduced from the Python documentation). Notice that if you follow this approach, the “simple” task is indeed simple, and the more complex tasks (like attaching binary objects or sending plain/HTML multipart messages) are accomplished very rapidly. For sending email … Read more