First of all, some insight on Stack And Heap Memory,
STACK::
When a program begins executing in the function main(), space is
allocated on the stack for all variables declared within main(). If
main() calls a function, additional storage is allocated for the
variables in that function at the top of the stack. Notice that the
parameters passed by main() to a function are also stored on the
stack. When the function returns, storage for its local variables is
deallocated. The memory allocated in the stack area is used and reused
during program execution. It should be clear that memory allocated in
this area will contain garbage values left over from previous usage.
HEAP::
We can make our program more flexible if, during execution, it could
allocate additional memory when needed and free memory when not
needed. Allocation of memory during execution is called dynamic memory
allocation. C provides library functions to allocate and free memory
dynamically during program execution. Dynamic memory is allocated on
the heap by the system.
Now, let's assume that you have to read a file, say 'abc.txt', but you don't know the size of file. The file can be just 1KB or it can be 10KB. So, it would not be good if you would make an array of char of size, let's say, 10*1024 bytes, because, when the file size would be just 1KB, you are just wasting the remaining amount of memory. So, in situations like these (and many other), you should be using malloc
after getting the size of file at run-time and you would free the memory after using it. Thus, optimized code using less amount of memory.
I just wanted to ask if there would be a need to use malloc() for values like int or bool in C.
No, there is no need though you can use. When a variable is defined in the source program, the type of the variable determines how much memory the compiler allocates. When the program executes, the variable consumes this amount of memory regardless of whether the program actually uses the memory allocated. This is particularly true for arrays and other primitive data types.