TCS Papers: Sample Questions 266 - 267 of 502

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 266

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Specify the 2 library functions to dynamically allocate memory?


  • 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);

Question number: 267

» Basic CS » Networks

Essay Question▾

Describe in Detail

What is OSPF?


  • Open Shortest Path First (OSPF) is a link state routing protocol (LSRP) using the Shortest Path First (SPF) or Dijkstra’s algorithm to calculate shortest connection path between known devices.

  • It is an Interior Gateway Protocol (IGP) routing Internet Protocol (IP) packets.

  • OSPF has following advantages:

    • Scales well

    • Can route traffic along multiple paths

    • Uses Internet’s topology to make accurate routing decisions

  • For example, to go from city A to city M there are two options:

  • Travel via cities B and C. The route would be ABCM. And the distance (or bandwidth cost) for A-B is miles, B-C is miles and C-M is 10 miles.

  • Travel via city F. The route would be AFM. And the distance for miles and F-M is miles.

  • Shortest route has least amount of total distance.

  • Thus, ABCM is the better option even though two cities have to be traversed. Second option with a single city has cost of .

  • OSPF does similar calculation for shortest path between the source and destination based on link bandwidth cost.

The OSPF (Open Shortest Path First)

The OSPF (Open Shortest Path First)

given the image is define the OSPF (Open Shortest Path First)