TCS Papers: Sample Questions 394 - 395 of 502

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

Question number: 394

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What is dynamic data structure?

Explanation

  • Dynamic data structure provides a means for storing data more efficiently into memory.

  • Using dynamic memory allocation, program allocates memory spaces as needed.

  • Contrast this with static data structure, wherein the programmer has to indicate fixed memory space to be used in the program.

  • Dynamic data structures grow and shrink as memory is allocated and deallocated from heap.

  • Dynamic data structures allocate blocks of memory from the heap and link those blocks into data structure using pointers.

  • When the data structure no longer needs a block of memory, it will return the block to the heap for reuse.

 Dynamic data structure

Dynamic Data Structure

Given the image is define the dynamic data structures and example

Question number: 395

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

Explanation

  • This is done by using %% in the printf statement.

  • For example, printf (“10%%”) will output “10%” on the screen.

  • The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications for each of the arguments

  • The character % is followed by one of the following characters.

  • The flag character

  • The field width

  • The precision

  • The length modifier

  • The conversion specifier:

  • So we can print “%” using “%%”.

  • Example

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     printf(“10%%”);
  5.     getchar();
  6.     return 0;
  7. }
  • Output:

10%