Languages-C & C Plus Plus [TCS Placement]: Sample Questions 29 - 30 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 29

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the difference between text files and binary files?

Explanation

  • Text files:
  • Text files contain data easily understood by humans- letters, numbers and other characters.
  • More restrictive than binary files since they can only contain textual data.
  • Unlike binary files, they are less likely to become corrupted- a small error in a binary file may make it unreadable
  • Text files may be saved in either a plain text (. TXT) format and rich text (. RTF) format.
  • A typical plain text file contains lines of text each followed by an End-of-Line (EOL) character.
  • An End-of-File (EOF) marker placed after the final character signals the end of the file.
  • Binary files:
  • Binary files contain 1s and 0s that only computers can interpret in 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 may include images, videos, or audio data.
  • Data will show up as garbled text in a text editor.

Question 30

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Specify the 2 library functions to dynamically allocate memory?

Explanation

  • malloc () and calloc () dynamically allocate memory
  • malloc () :
    • Stands for “memory allocation” .
    • Reserves a block of memory of specified size and returns a pointer of type void which can be casted into pointer of any form.
    • Syntax: ptr = (cast-type ⚹) malloc (byte-size)
    • Here, “ptr” is pointer of “cast-type” . The malloc () function returns a pointer to an area of memory with size of “byte-size” .
    • If the space is insufficient allocation fails and NULL pointer is returned.
  • Calloc ()
  • The name calloc stands for “contiguous allocation” .
  • The only difference between malloc () and calloc () is that, malloc () allocates single block of memory whereas calloc () allocates multiple blocks of memory each of same size and sets all bytes to zero.
  • Syntax:

ptr = (cast-type ⚹) calloc (n, element-size) ;

Developed by: