This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Standard Definition”.
Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.
1. Some types and macros defined under the header file stddef.h may be defined under other header files too.
a) True
b) False
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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 <stddef.h> 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
View Answer
Explanation: 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 <stddef.h> 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
View Answer
Explanation: 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
View Answer
Explanation: 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 <stdlib.h> #include <stdio.h> 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: 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.
Sanfoundry Global Education & Learning Series – C Programming Language.
To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Check Computer Science Books
- Check C Books
- Apply for C Internship
- Practice Computer Science MCQs
- Apply for Computer Science Internship