The buffer is something that we declare when we write the program just like we declare an array or is it something that’s already in the computer.
- List item
If I declare char buffer[MAX_LENGTH],is the buffer ,which I declare ,a buffer?
- List item
Book called Pointers On C says the function sprintf() write values to the buffer.This is the function prototype from the book.int sprintf(char*buffer,char const * format,...)Is the buffer in this function prototype a buffer or just an array whose name happens to be buffer?
#include<stdio.h>
#include<string.h>
int main(void)
{
char buffer[50]={0};
sprintf(buffer,"%c%c%c",'a','b','c');
puts(buffer);
return 0;
}
The result is abc.So is the buffer just a ordinary array?Is the buffer here absolutely different with the buffer in I/O?If the buffer here just an ordinary array,then why is the first argument in this function prototype in such a misleading way, instead of just declaring it as char*arr?
>Solution :
buffer is nothing more than a chunk of memory used to store the data. So if you store characters – it will be simply a char array.
If your data has another type, you will need "a simple" array of that type. Example: jf you want to store double you will need array of doubles
Of course, every array of something is just a chunk of memory.
In declaration:
int sprintf(char * restrict s, const char * restrict format, ...);
function sprintf takes pointers to char as parameters, but those pointers simply reference some chunks of memory. You can call them bufferes.