C MCQ with Answers



                                          C MCQ with Answers

1. What will be the output of the following C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *p = NULL;
  5.         char *q = 0;
  6.         if (p)
  7.             printf(" p ");
  8.         else
  9.             printf("nullp");
  10.         if (q)
  11.             printf("q\n");
  12.         else
  13.             printf(" nullq\n");
  14.     }
a) nullp nullq
b) Depends on the compiler
c) x nullq where x can be p or nullp depending on the value of NULL
d) p q
Answer: a


2. Comment on the following C statement.
const int *ptr;
a) You cannot change the value pointed by ptr
b) You cannot change the pointer ptr itself
c) You May or maynot change the value pointed by ptr
d) You can change the pointer as well as the value pointed by it
Answer: a

3. Comment on the following pointer declaration.
int *ptr, p;
a) ptr is a pointer to integer, p is not
b) ptr and p, both are pointers to integer
c) ptr is a pointer to integer, p may or may not be
d) ptr and p both are not pointers to integer
Answer: a

4. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;)?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
Answer: a



5. What will be the output of the following C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         char *str = "hello, world";
  5.         char *str1 = "hello, world";
  6.         if (strcmp(str, str1))
  7.             printf("equal");
  8.         else
  9.             printf("unequal");
  10.     }
a) equal
b) unequal
c) Compilation error
d) Depends on the compiler
Answer: b


6. String operation such as strcat(s, t), strcmp(s, t), strcpy(s, t) and strlen(s) heavily rely upon.
a) Presence of NULL character
b) Presence of new-line character
c) Presence of any escape sequence
d) None of the mentioned
Answer: a




7. Which of the following cannot be a structure member?
a) Another structure
b) Function
c) Array
d) None of the mentioned
Answer: b




8. What will be the output of the following C code?
  1.     #include <stdio.h>
  2.     struct
  3.     {
  4.         int k;
  5.         char c;
  6.     } p;
  7.     int p = 10;
  8.     int main()
  9.     {
  10.         p.k = 10;
  11.         printf("%d %d\n", p.k, p);
  12.     }
a) Compile time error
b) 10 10
c) Depends on the standard
d) Depends on the compiler
Answer: a




9. What would be the size of the following union declaration? (Assuming size of double = 8, size of int = 4, size of char = 1)
  1.     #include <stdio.h>
  2.     union uTemp
  3.     {
  4.         double a;
  5.         int b[10];
  6.         char c;
  7.     }u;
a) 4
b) 8
c) 40
d) 80
Answer: c



10. What will be the output of the following C code (Assuming size of int and float is 4)?
  1.     #include <stdio.h>
  2.     union
  3.     {
  4.         int ival;
  5.         float fval;
  6.     } u;
  7.     void main()
  8.     {
  9.         printf("%d", sizeof(u));
  10.     }
a) 16
b) 8
c) 4
d) 32
Answer: c

Comments

Popular posts from this blog

What are Keywords in C?

Features of C language

Structure in C