1.You are writing an application that handles voter registration. Let’s say you will be using malloc to store a string that contains “Boston”. What should you be using as an argument to malloc?
1. The argument to malloc
is the number of bytes to
be allocated.
Every string in C has a "\0" character at the end.
That means , if the length of string is n you need to allocate n+1 bytes.
Here malloc is taking the the number of bytes to be allocated for the string (6 characters for "Boston" and 1 for "\0")
new_string = (char*) malloc((n+1)*sizeof(char));
2. This can be understood from an example case with a long running cpu process and short i/o bound processes.
Consider a situation when many IO bound processes are there and one CPU bound process. The IO bound processes have to wait for CPU bound process when CPU bound process acquires CPU. The IO bound process could have better taken CPU for some time, then used IO devices. This is called convoy effect.
Get Answers For Free
Most questions answered within 1 hours.