Important Program of C language in O level exam january 2019
Important Program of C language in O level exam january 2019
All files can be categorized into
one of two file formats — binary or text. The two file types may look the same
on the surface, but they encode data
differently.
Binary Files
Binary files typically
contain a sequence of bytes, or ordered
groupings of eight bits. When creating a custom file
format for a program, a developer arranges these bytes into a format that
stores the necessary information for the application. Binary file formats may
include multiple types of data in the same file, such as image, video, and
audio data. This data can be interpreted by supporting programs, but will show
up as garbled text in a text editor. Below is an example of a .PNG image file opened in an image viewer and a text
editor
Text Files
Text files are more
restrictive than binary files since they can only contain textual data.
However, unlike binary files, they are less likely to become corrupted. While a
small error in a binary file may make it unreadable, a small error in a text
file may simply show up once the file has been opened. This is one of reasons
Microsoft switched to a compressed text-based XML format for
the Office 2007 file types.
Text files may be saved
in either a plain text (.TXT) format and rich text (.RTF) format. A typical
plain text file contains several lines of text that are each followed by an
End-of-Line (EOL) character. An End-of-File (EOF) marker is placed after the
final character, which signals the end of the file. Rich text files use a
similar file structure, but may also include text styles, such as bold and
italics, as well as page formatting information. Both plain text and rich text
files include a (character encoding| character encoding) scheme that determines
how the characters are interpreted and what characters can be displayed.
calloc() vs malloc()
The name malloc and
calloc() are library functions that allocate memory dynamically. It means that
memory is allocated during runtime(execution of the program) from heap segment.
Initialization: malloc()
allocates memory block of given size (in bytes) and returns a pointer to the
beginning of the block. malloc() doesn’t initialize the allocated memory. If we
try to acess the content of memory block then we’ll get garbage values.
syntax-:
void * malloc( size_t size );
calloc() allocates the memory and
also initializes the allocates memory block to zero. If we try to access the
content of these blocks then we’ll get 0
syntax:-
void * calloc( size_t num, size_t size );
Number of
arguments: Unlike malloc(), calloc() takes two arguments:
1) Number of blocks to be allocated.
2) Size of each block.
2) Size of each block.
Return Value: After successfull allocation in malloc() and calloc(), a pointer to the block of memory is returned otherwise NULL value is returned which indicates the failure of allocation.
Comments
Post a Comment