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.

250+ TOP MCQs on Signed Qualifier and Answers

C Multiple Choice Questions & Answers (MCQs) on “Signed Qualifier”.

1. In a signed integer, the sign is represented by ___________
a) Least significant bit
b) Most significant bit
c) System dependent
d) The mean of the most significant bit and the least significant bit
Answer: b
Clarification: In a signed integer, the most significant bit represents the sign whereas, in an unsigned integer, no bit is used to represent the sign.

2. Sign qualifiers can be applied to double.
a) True
b) False
Answer: b
Clarification: Sign qualifiers cannot be applied to the data types: float and double

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

#include
int main()
{
    signed char ch= ‘a’;
    printf(%u”,ch);
    return 0;
}

a) -65
b) 65
c) -97
d) 97
Answer: d
Clarification: Only for completeness, sign qualifiers are available with char data type.

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

#include
main()
{
    signed char a[]= “BAT”;
    printf(%c”, a[1]);
    return 0;
}

a) -A
b) BAT
c) A
d) 65
Answer: c
Clarification: Sign qualifiers are available for char data types only for completeness. Format specifier used: %c, which prints a character. a[1] will print ‘A’.

5. What is the default state of an integer in c language?
a) Signed
b) Unsigned
c) System dependent
d) There is no default state
Answer: a
Clarification: The default state of an integer in c language is signed. Hence we can store both positive and negative integer values in it.

6. Suppose we have: int a=100; (signed by default).
If we want to convert this to an unsigned long integer, we can do this by making the following small change:
a) int a=lu100;
b) int a= 100ul;
c) int a=uu100;
d) int a=100uu;
Answer: b
Clarification: An integer literal can have a suffix that is a combination of U and L( uppercase or lowercase). The prefix specifies the base or the radix, ie: 0x for hexadecimal, 0 for octal and nothing for decimal.

7. What is the binary representation of the integer -14?
a) 11110
b) 01110
c) 01100
d) 11100
Answer: a
Clarification: The left most bit (most significant bit) is used to represent the sign of the number: 0 for positive and 1 for negative. For example, a value of positive 14 is written as 01110(in binary). But a value of negative 14 is written as: 11110.

8. Which of the following header files must necessarily be included in your code, if you want to find the minimum value of unsigned short integer?
a) stdio.h
b) stdlib.h
c) limits.h
d) math.h
Answer: c
Clarification: The header file limits.h is used to find the value of constants such as minimum and maximum. stdio.h: standard input and output, stdlib.h: standard library, math.h: mathematics functions library

9. What will be the error in the following C code?

main()
{
    long float a=-25.373e22;
    printf("%lf",a);
}

a) Negative number cannot be assigned to float data type
b) Long and float cannot be used together
c) Does not result in error
d) Logical error
Answer: b
Clarification: It is not possible to use sign qualifier with float data type, however in the above code a negative value has been assigned to the variable without the use of sign qualifiers, which is possible. Hence, the answer is not “negative number cannot be assigned to float data type”. we know that size qualifier long is not applicable for float data type, hence the error.

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

main()
{
    unsigned a=10;
    long unsigned b=5l;
    printf(%lu%u”,a,b);
}

a) 105
b) 510
c) 10
d) error
Answer: a
Clarification: The format specifiers which are for unsigned and long unsigned have been used in the code. Had we used the format specifiers in the reverse order, the output would still be the same.

250+ TOP MCQs on Bitwise Operators and Answers

’s MCQs on C helps anyone preparing for placement in HCL and other companies. Anyone looking for HCL placement papers should practice these questions continuously for 2-3 months, thereby ensuring a top position in placements.

Here is a listing of C questions on “Bitwise Operators” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5, b = -7, c = 0, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("n%d%d%d%d", a, b, c, d);
  7.     }

a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int a = -5;
  5.         int k = (a++, ++a);
  6.         printf("%dn", k);
  7.     }

a) -3
b) -5
c) 4
d) Undefined
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2;
  5.         x = x << 1;
  6.         printf("%dn", x);
  7.     }

a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         x = x >> 1;
  6.         printf("%dn", x);
  7.     }

a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         if (~0 == 1)
  5.             printf("yesn");
  6.         else
  7.             printf("non");
  8.     }

a) yes
b) no
c) compile time error
d) undefined
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = -2;
  5.         if (!0 == 1)
  6.             printf("yesn");
  7.         else
  8.             printf("non");
  9.     }

a) yes
b) no
c) run time error
d) undefined
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 0;
  5.         if (1 |(y = 1))
  6.             printf("y is %dn", y);
  7.         else
  8.             printf("%dn", y);
  9.  
  10.     }

a) y is 1
b) 1
c) run time error
d) undefined
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 1;
  5.         if (y & (y = 2))
  6.             printf("true %dn", y);
  7.         else
  8.             printf("false %dn", y);
  9.  
  10.     }

a) true 2
b) false 2
c) either true 2 or false 2
d) true 1
Answer: a
Clarification: None.

250+ TOP MCQs on While Loops and Answers

online C test on “While Loops”. One shall practice these test questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our online C test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of online C test questions on “While Loops” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     int main()
  3.     {
  4.         while ()
  5.             printf("In while loop ");
  6.         printf("After loopn");
  7.     }

a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         do
  5.             printf("In while loop ");
  6.         while (0);
  7.             printf("After loopn");
  8.     }

a) In while loop
b)

   In while loop
   after loop

c) After loop
d) Infinite loop
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         do {
  6.             i++;
  7.             printf("In while loopn");
  8.         } while (i < 3);
  9.     }

a)

   In while loop
   In while loop
   In while loop

b)

   In while loop
   In while loop

c) Depends on the compiler
d) Compile time error
Answer: a
Clarification: None.

4. How many times i value is checked in the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         do {
  6.             i++;
  7.             printf("in while loopn");
  8.         } while (i < 3);
  9.     }

a) 2
b) 3
c) 4
d) 1
Answer: b
Clarification: None.

5. How many times i value is checked in the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         while (i < 3)
  6.             i++;
  7.         printf("In while loopn");
  8.     }

a) 2
b) 3
c) 4
d) 1
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 2;
  5.         do
  6.         {
  7.             printf("Hi");
  8.         } while (i < 2)
  9.     }

a) Compile time error
b) Hi Hi
c) Hi
d) Varies
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         while (++i)
  6.         {
  7.             printf("H");
  8.         }
  9.     }

a) H
b) H is printed infinite times
c) Compile time error
d) Varies
Answer: b
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0;
  5.         do
  6.         {
  7.             printf("Hello");
  8.         } while (i != 0);
  9.     }

a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error
Answer: c
Clarification: None.

250+ TOP MCQs on Register Variables and Answers

C Objective Questions on “Register Variables” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register int i = 10;
  5.         int *p = &i;
  6.         *p = 11;
  7.         printf("%d %dn", i, *p);
  8.     }

a) Depends on whether i is actually stored in machine register
b) 10 10
c) 11 11
d) Compile time error

Answer: d
Clarification: None.

2. register keyword mandates compiler to place it in machine register.
a) True
b) False
c) Depends on the standard
d) None of the mentioned

Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register static int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register auto int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         register const int i = 10;
  5.         i = 11;
  6.         printf("%dn", i);
  7.     }

a) 10
b) Compile time error
c) Undefined behaviour
d) 11

Answer: b
Clarification: None.

6. Register storage class can be specified to global variables.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard

Answer: b
Clarification: None.

7. Which among the following is wrong for “register int a;”?
a) Compiler generally ignores the request
b) You cannot take the address of this variable
c) Access time to a is critical
d) None of the mentioned

Answer: d
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         register int x = 5;
  5.         m();
  6.         printf("x is %d", x);
  7.     }
  8.     void m()
  9.     {
  10.         x++;
  11.     }

a) 6
b) 5
c) Junk value
d) Compile time error

Answer: d
Clarification: None.

250+ TOP MCQs on Pointers and Arrays and Answers

C quiz on “Pointers and Arrays”. One shall practice these quizzes to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C quiz comes with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C quiz on “Pointers and Arrays” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int a[3] = {1, 2, 3};
  5.         int *p = a;
  6.         printf("%pt%p", p, a);
  7.     }

a) Same address is printed
b) Different address is printed
c) Compile time error
d) Nothing
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s = "hello";
  5.         char *p = s;
  6.         printf("%pt%p", p, s);
  7.     }

a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
Answer: b
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s= "hello";
  5.         char *p = s;
  6.         printf("%ct%c", p[0], s[1]);
  7.     }

a) Run time error
b) h h
c) h e
d) h l
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s= "hello";
  5.         char *p = s;
  6.         printf("%ct%c", *(p + 3),  s[1]);
  7.     }

a) h e
b) l l
c) l o
d) l e
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *s= "hello";
  5.         char *p = s;
  6.         printf("%ct%c", 1[p], s[1]);
  7.     }

a) h h
b) Run time error
c) l l
d) e e
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void foo( int[] );
  3.     int main()
  4.     {
  5.         int ary[4] = {1, 2, 3, 4};
  6.         foo(ary);
  7.         printf("%d ", ary[0]);
  8.     }
  9.     void foo(int p[4])
  10.     {
  11.         int i = 10;
  12.         p = &i;
  13.         printf("%d ", p[0]);
  14.     }

a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%dn", p[-2]);
  7.     }

a) 1
b) 2
c) Compile time error
d) Some garbage value
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int ary[4] = {1, 2, 3, 4};
  5.         int *p = ary + 3;
  6.         printf("%d %dn", p[-2], ary[*p]);
  7.     }

a) 2 3
b) Compile time error
c) 2 4
d) 2 somegarbagevalue
Answer: d
Clarification: None.