Machine-translated by Google. Questions are authored in English.
Top

Typedef Questions and Answers

61.

Which of the following header files must necessarily be included to use dynamic memory allocation functions?

Answer: A

Correct answer: stdlib.h

stdlib.h declares malloc, calloc, realloc and free, along with size_t.

Including it matters more than it may appear. Without the prototype, an older compiler assumes malloc returns int, and on a machine where a pointer is wider than an int the returned address is truncated - a fault that a cast to the target type will silence rather than reveal. That is one of the strongest arguments against casting the result in C.

Please log in or register to report this question.

62.

What will be the output of the program?

#include <stdio.h>

int main()
{
    typedef float f;
    static f *fptr;
    float fval = 90;
    fptr = &fval;
    printf("%f\n", *fptr);
    return 0;
}

 

Answer: B

Correct answer: 90.000000

f is an alias for float, so f *fptr is a float *. It is assigned the address of fval, and *fptr retrieves 90. Passed to printf, a float is promoted to double and %f prints it with six decimal places, giving 90.000000 rather than 90. The static qualifier affects storage duration only.

Please log in or register to report this question.

63.

typedef's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas #define's always have a global effect.

Answer: A

Correct answer: Yes

The statement is correct, and it follows from where each is processed. A typedef is a declaration handled by the compiler, so it obeys the ordinary scope rules and one declared inside a function or block is invisible outside it. A #define is handled by the preprocessor, which knows nothing of blocks, so it applies from its definition to the end of the file or until #undef.

Please log in or register to report this question.

Loading…
Tags: Typedef Questions and Answers || Typedef MCQ Questions and Answers || Typedef GK Questions and Answers || Typedef GK MCQ Questions || Typedef Multiple Choice Questions and Answers || Typedef GK || GK on Typedef || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming