M
M
memogolik2021-10-28 22:08:46
C++ / C#
memogolik, 2021-10-28 22:08:46

How to write normally: for (int i = 0; ...) or for (int i = NULL; ...)?

How will it normally write 0 or NULL in expressions like int i = 0 ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Armenian Radio, 2021-10-28
@memogolik

NULL is a service define, which is, in particular, in Windows.
The common practice is int i = 0; At least because it's shorter.
The problem is different. In int.
In most languages, an int is 32 signed bits, that is, two gigabytes. In modern memory systems, there are tens-hundreds-thousands of gigabytes, and programs process various kinds of big data and ML. So indexing an array with ints can easily lead to subtle bugs.
Therefore, it is correct to write for(size_t i = 0; ..

T
Tony, 2021-10-29
@AntonSazonov

int i = 0
NULLapply to pointers. Moreover, NULL is a Windows OS macro. This has nothing to do with the C++ language.
C++ uses nullptr for pointers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question