coal
then under what context would it not allocate memory
klimi
When there is no more memory to allocate
coal
w e l l
coal
that makes sense lol
coal
thats the size of the pointer
klimi
The return type of malloc is just a pointer... If you cast it into char pointer, it is still a pointer... There is no information about the size itself
coal
do sizeof(ptr)/sizeof(ptr[0])
coal
but the return is also implementation defined
coal
for example, if you try to allocate a size 0, it can return null, or sometimes even a non-null pointer
klimi
Heap is not a stack
coal
i mean its a stack in the sense that summing 1 to the pointer would return you the element after the current address
klimi
You mean that's "its a memory"?
coal
like, ptr[1] is literally short for "sum 1 to the pointer"
klimi
Its syntax sugar and it has nothing to do with stack or heap
klimi
You can do pointer arithmetics even in the static section
coal
You mean that's "its a memory"?
i mean that a pointer is only as big as its memory allocated, and whenever there is space there can be elements after the pointer's address
coal
Its syntax sugar and it has nothing to do with stack or heap
its syntax sugar yes, also [] operator is order-agnostic
coal
you can as well do 0[ptr]
coal
its a sum, you're just working on top of the memory layout in a pointer
klimi
you can as well do 0[ptr]
Yeah, syntax sugar
klimi
size /= big
Elaborate
coal
Elaborate
the pointer can cover up to as much memory it was allocated at its address
coal
No
what
klimi
Pointer can point anywhere
coal
pointer can point anywhere then what does malloc do
klimi
Its just a number
coal
it indeed is a number thank you
coal
im talking about the memory layout that you interact with when dealing with pointers
coal
a pointer points to a memory address and thats it
klimi
pointer can point anywhere then what does malloc do
Malloc tries to allocate memory on the heap, if it is successful, it returns the pointer to the start address
coal
ill reformulate my statement
coal
a pointer itself has no size, but it covers only as much as the memory allocated for such
klimi
You can have 2 arrays next to each other and you can use the first pointer to point to the second array
klimi
Pointer covers all the virtual memory
ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
Malloc tries to allocate memory on the heap, if it is successful, it returns the pointer to the start address
Can a function be created to allocate memory? I mean a function which is user defined
coal
what was the original topic again
klimi
what was the original topic again
That pointer covers some memory, and I still dont understand what you mean by that
coal
That pointer covers some memory, and I still dont understand what you mean by that
no that was the debate we started after my misconception
coal
i understand what you said and you're right, i had a wrong idea of pointers regarding to their "scope"
coal
i joined this group especially to learn and help if i can
coal
so thank you as well
klimi
Oh no problem, I am here to discuss various topics. There is always things to learn
coal
agreed
Dastan
What is difference between do while and while
Dastan
?
coal
What is difference between do while and while
do executes before checking the condition
coal
while executes after checking it
coal
as a matter of fact, do while will always run at least once: do { std::cout << "This is printed" } while (0); while (0) { std::cout << "This wont be printed"; }
coal
it is also useful when you're receiving input, as the variables in the loop context are also accesible from the condition: std::string input; do { std::cin >> input; } while (input);
\Device\NUL
it is also useful when you're receiving input, as the variables in the loop context are also accesible from the condition: std::string input; do { std::cin >> input; } while (input);
You can also do that with this int input; while (std::cin >> input) { if (!input) break; } https://isocpp.org/wiki/faq/input-output#stream-input-failure
coal
both are good approaches though
\Device\NUL
while(std::cin>>input, !input){ do some stuff } perhaps? hehe
Did you mean while(std::cin>>input && !input) ?
Suka
Did you mean while(std::cin>>input && !input) ?
yups but i guess we can use , as separator? cmiiw
coal
#include <iostream> int main() { int input; while (std::cin >> input, input) { std::cout << "Received input: " << input; } return 0; }
coal
try compiling this
A R A B I A N
Uh..Hello guys
A R A B I A N
Please I need a good YouTube tutorial for C++🙏🙏
coal
/get cppbookguide
\Device\NUL
, is also valid
Ow, I didn't know that
coal
Ow, I didn't know that
me neither but its good to know
Suka
its old school stuff hehe
olli
But i can access by base address imean pointer
you can't access the last element of an array by only knowing the array's starting address.