250+ TOP MCQs on Standard Definition and Answers

C MCQs on “Standard Definition”.

1. Some types and macros defined under the header file stddef.h may be defined under other header files too.
a) True
b) False
Answer: a
Clarification: There are some types and macros which are defined under various other header files, in addition to being defined under stddef.h. For example, the type size_t is defined under stdio.h, stdlib.h, string.h etc in addition to being defined under stddef.h.

2. size_t is of ______________ type.
a) signed integer
b) signed character
c) unsigned integer
d) unsigned character
Answer: c
Clarification: size_t, defined under stddeh, is of the type unsigned integer. It is returned by the sizeof() operator.

3. Which of the following returns a signed integer type on finding the difference between two pointers to elements in the same array?
a) __cptrdiff__
b) cptrdiff_t
c) __ptrdiff__
d) ptrdiff_t
Answer: d
Clarification: ptrdiff_t is used for pointer arithmetic and array indexing. Only pointers to elements of the same array may be subtracted from each other.

4. What will be the output of the following C code?

#include 
int main(void)
{
    int num[10];
    int *p1=&num[14], *p2=&num[19];
    ptrdiff_t a = p1-p2;
    printf("%d", a);
}

a) 5
b) -5
c) error
d) 10
Answer: b
Clarification: The type ptrdiff_t, defined under the file stddef is used to find the difference between two pointers pointing to elements of the same array. Hence the output of the above code is -5.

5. What will be the output of the following C code?

#include 
int main(void)
{
    int num[15];
    int *p1=&num['a'], *p2=&num['A'];
    ptrdiff_t d = p1-p2;
    printf("%d", d);
}

a) 15
b) -32
c) 32
d) error
Answer: c
Clarification: The ASCII value ‘a’ is 97 and that of ‘A’ is 65. Their difference is equal to 32. Hence the output of the code shown above is 32.

6. Which of the following is not defined under the header file stddef.h?
a) size_t
b) ptrdiff_t
c) exp_t
d) null
Answer: c
Clarification: size_t, ptrdiff_t and NULL are defined under the file stddef.h. There is no type called exp_t c language.

7. Point out the error (if any) in the following C code?

#include 
#include 
int main(void)
{
    int* p = NULL;
    struct S *s = NULL;
    void(*f)(int, double) = NULL;
    char *ptr = malloc(15);
    if (ptr == NULL) printf("Out of memory");
    free(ptr);
}

a) Error in the statement: void(*f)(int, double) = NULL;
b) Error in the statement: char *ptr = malloc(15);
c) Error in the statement: struct S*s = NULL;
d) No error
Answer: d
Clarification: The code shown above does not result in an error. However, since ptr is not equal to NULL, it does not print anything.

8. A type whose alignment requirement is at least as large as that of every data type ____________
a) max_align_t
b) ptrdiff_t
c) size_t
d) null
Answer: d
Clarification: The alignment of the type max_align_t is at least as great as that supported by the compiler in all contexts. An extended alignment is greater than the alignment of max_align_t type. A type having an extended alignment requirement is also called over aligned.

9. The macro offset expands to a constant of type __________________
a) size_t
b) print_t
c) ptrdiff_t
d) null
Answer: a
Clarification: offsetof expands to a constant of type size_t. It retuns the offset of the field member from the start to of the structure type.

10. When we use multiple alignas specifiers in the same declaration, the ____________ one is used.
a) first
b) strictest
c) last
d) middle
Answer: b
Clarification: alignas is one of the types used to modify the alignment requirement of the object being declared. When more than one alignas specifier is used in the same declaration, the strictest one is used.

Leave a Reply

Your email address will not be published. Required fields are marked *