Languages-C & C Plus Plus [TCS Placement]: Sample Questions 99 - 100 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 99

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Name of the classes that are introduced in the System. Numerics namespace.

Explanation

  • The following two new classes are introduced in the System. Numerics namespace.
  • BigInteger -
    • Non-primitive integral type to hold a value of any size.
    • No lower and upper limit allowing arithmetic calculations with very large numbers which cannot be held by double or long.
    • Complex -
  • Represents complex numbers enabling arithmetic operations with complex numbers.
  • Complex number is represented in the form a + bi, where a is the real part and b is the imaginary part.

Question 100

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Why does malloc (0) return valid memory address? what՚s the use?

Explanation

malloc (0) does not return a non-NULL under every implementation. An implementation is free to behave in a manner it finds suitable, if the allocation size requested is zero. The implmentation may choose any of the following actions:

  • A null pointer is returned.
  • The behavior is same as if a space of non-zero size was requested. In this case, the usage of return value yields to undefined-behavior.
  • If the implementation returns a non-NULL value for a request of a zero-length space, a pointer to object of ZERO length is returned- How would object of zero size should be represented?
  • For implementations that return non-NULL values, a typical usage is as follows: void func (void) {int ⚹ p; / ⚹ p is a one-dimensional array, whose size will vary during the the lifetime of the program ⚹ /size_t c; p = malloc (0) ; / ⚹ initial allocation ⚹ /if (! p) {perror ( “FAILURE” ) ; return;} / ⚹ … ⚹ /while (1) {c = (size_t) … ; / ⚹ Calculate allocation size ⚹ /p = realloc (p, c ⚹ sizeof ⚹ p) ; / ⚹ use p, or break from the loop ⚹ // ⚹ … ⚹ /} return;}
  • Notice that this program is not portable, since an implementation is free to return NULL for a malloc (0) request, as the C Standard does not support zero-sized objects.

Developed by: