250+ TOP MCQs on Arithmetic Operators and Answers

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

Here is a listing of C test questions on “Arithmetic 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 = 3;
  5.         int b = ++a + a++ + --a;
  6.         printf("Value of b is %d", b);
  7.     }

a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer: d
Clarification: None.

2. What is the precedence of arithmetic operators (from highest to lowest)?
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
Answer: a
Clarification: None.

3. Which of the following is not an arithmetic operation?
a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;
Answer: c
Clarification: None.

4. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
Answer: d
Clarification: None.

5. Which among the following are the fundamental arithmetic operators, i.e, performing the desired operation can be done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10;
  5.         double b = 5.6;
  6.         int c;
  7.         c = a + b;
  8.         printf("%d", c);
  9.     }

a) 15
b) 16
c) 15.6
d) 10
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10, b = 5, c = 5;
  5.         int d;
  6.         d = a == (b + c);
  7.         printf("%d", d);
  8.     }

a) Syntax error
b) 1
c) 10
d) 5
Answer: b
Clarification: None.

250+ TOP MCQs on Precedence and Order of Evaluation and Answers

’s MCQs on C helps anyone preparing for placement in Accenture and other companies. Anyone looking for Accenture 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 “Precedence and Order of Evaluation” along with answers, explanations and/or solutions:

1. Which of the following are unary operators?
a) sizeof
b) –
c) ++
d) all of the mentioned
Answer: d
Clarification: None.

2. Where in C the order of precedence of operators do not exist?
a) Within conditional statements, if, else
b) Within while, do-while
c) Within a macro definition
d) None of the mentioned
Answer: d
Clarification: None.

3. Associativity of an operator is ___________
a) Right to Left
b) Left to Right
c) Random fashion
d) Both Right to Left and Left to Right
Answer: d
Clarification: None.

4. Which of the following method is accepted for assignment?
a) 5 = a = b = c = d;
b) a = b = c = d = 5;
c) a = b = 5 = c = d;
d) None of the mentioned
Answer: b
Clarification: None.

5. Which of the following is NOT possible with any 2 operators in C?
a) Different precedence, same associativity
b) Different precedence, different associativity
c) Same precedence, different associativity
d) All of the mentioned
Answer: c
Clarification: None.

6. Which of the following is possible with any 2 operators in C?
a) Same associativity, different precedence
b) Same associativity, same precedence
c) Different associativity, different precedence
d) All of the mentioned
Answer: d
Clarification: None.

7. Which of the following operators has the lowest precedence?
a) !=
b) &&
c) ?:
d) ,
Answer: d
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 3, i = 0;
  5.         do {
  6.             x = x++;
  7.             i++;
  8.         } while (i != 3);
  9.         printf("%dn", x);
  10.     }

a) Undefined behaviour
b) Output will be 3
c) Output will be 6
d) Output will be 5
Answer: c
Clarification: None.

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

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

a) 0, 4, 2, 1
b) 0, 5, 2, 1
c) -1, 4, 1, 1
d) 0, 5, 1, 0
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int p = 10, q = 20, r;
  5.         if (r = p = 5 || q > 20)
  6.             printf("%d", r);
  7.         else
  8.             printf("No Outputn");
  9.     }

a) 1
b) 10
c) 20
d) No Output
Answer: a
Clarification: None.

250+ TOP MCQs on External Variables and Answers

C questions and puzzles on “External Variables”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles 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 questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C questions and puzzles on “External Variables” 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.         m();
  5.         printf("%d", x);
  6.     }
  7.     int x;
  8.     void m()
  9.     {
  10.         x = 4;
  11.     }

a) 4
b) Compile time error
c) 0
d) Undefined
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int x;
  3.     void main()
  4.     {
  5.         printf("%d", x);
  6.     }

a) Junk value
b) Run time error
c) 0
d) Undefined
Answer: c
Clarification: None.

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

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

a) Run time error
b) 3 3
c) 3 5
d) 3 4
Answer: d
Clarification: None.

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

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

a) 3 3
b) 3 4
c) 3 5
d) Run time error
Answer: a
Clarification: None.

5. Functions in C are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions
Answer: b
Clarification: None.

6. Global variables are ____________
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
Answer: b
Clarification: None.

7. Which of the following is an external variable in the following C code?

  1.     #include 
  2.     int func (int a)
  3.     {
  4.         int b;
  5.         return b;
  6.     }
  7.     int main()
  8.     {
  9.         int c;
  10.         func (c);
  11.     }
  12.     int d;

a) a
b) b
c) c
d) d
Answer: d
Clarification: None.

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

  1.      #include 
  2.     int main()
  3.     {
  4.         printf("%d", d++);
  5.     }
  6.     int d = 10;

a) 9
b) 10
c) 11
d) Compile time error
Answer: d
Clarification: None.

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

  1.     #include 
  2.     double var = 8;
  3.     int main()
  4.     {
  5.         int var = 5;
  6.         printf("%d", var);
  7.     }

a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name
Answer: a
Clarification: None.

250+ TOP MCQs on Conditional Inclusion and Answers

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

Here is a listing of C Objective Questions on “Conditional Inclusion” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     #define SYSTEM 20
  3.     int main()
  4.     {
  5.         int a = 20;
  6.         #if SYSTEM == a
  7.         printf("HELLO ");
  8.         #endif
  9.         #if SYSTEM == 20
  10.         printf("WORLDn");
  11.         #endif
  12.     }

a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
Answer: b
Clarification: None.

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

  1.     #include 
  2.     #define Cprog
  3.     int main()
  4.     {
  5.         int a = 2;
  6.         #ifdef Cprog
  7.         a = 1;
  8.         printf("%d", Cprog);
  9.     }

a) No output on execution
b) Output as 1
c) Output as 2
d) Compile time error
Answer: d
Clarification: None.

3. The “else if” in conditional inclusion is written by?
a) #else if
b) #elseif
c) #elsif
d) #elif
Answer: d
Clarification: None.

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

  1.     #include 
  2.     #define COLD
  3.     int main()
  4.     {
  5.         #ifdef COLD
  6.         printf("COLDt");
  7.         #undef COLD
  8.         #endif
  9.         #ifdef COLD
  10.         printf("HOTt");
  11.         #endif
  12.     }

a) HOT
b) COLD
c) COLD HOT
d) No Output
Answer: b
Clarification: None.

5. Which of the following sequences are unaccepted in C language?
a)

b)

c)

d)

View Answer

Answer: c
Clarification: None.

 
 

6. In a conditional inclusion, if the condition that comes after the if is true, then what will happen during compilation?
a) Then the code up to the following #else or #elif or #endif is compiled
b) Then the code up to the following #endif is compiled even if #else or #elif is present
c) Then the code up to the following #eliif is compiled
d) None of the mentioned
Answer: a
Clarification: None.

7. Conditional inclusion can be used for ___________
a) Preventing multiple declarations of a variable
b) Check for existence of a variable and doing something if it exists
c) Preventing multiple declarations of same function
d) All of the mentioned
Answer: d
Clarification: None.

8. The #elif directive cannot appear after the preprocessor #else directive.
a) True
b) False
Answer: a
Clarification: None.

250+ TOP MCQs on Initialization of Pointer Arrays and Answers

C quiz on “Initialization of Pointer 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 “Initialization of Pointer Arrays” along with answers, explanations and/or solutions:

1. Which of the following is the correct syntax to declare a 3 dimensional array using pointers?
a) char *a[][];
b) char **a[];
c) char ***a;
d) all of the mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char *a = {"p", "r", "o", "g", "r", "a", "m"};
  5.         printf("%s", a);
  6.     }

a) Output will be program
b) Output will be p
c) No output
d) Compile-time error
Answer: b
Clarification: None.

3. An array of strings can be initialized by _________
a) char *a[] = {“Hello”, “World”};
b) char *a[] = {“Hello”, “Worlds”};
c)

char *b = "Hello";
char *c = "World";
char *a[] = {b, c};

d) all of the mentioned
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0;
  6.         for (i = 0;i < 10; i++)
  7.         printf("%s", *(a[i]));
  8.     }

a) segmentation fault
b) hi hello how followed by 7 null values
c) 10 null values
d) depends on compiler
Answer: a
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0, j = 0;
  6.         a[0] = "hey";
  7.         for (i = 0;i < 10; i++)
  8.         printf("%sn", a[i]);
  9.     }

a) hi hello how Segmentation fault
b) hi hello how followed by 7 null values
c) hey hello how Segmentation fault
d) depends on compiler
Answer: c
Clarification: None.

6. What will be the output of the following C code on a 32-bit system?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         printf("%dn", sizeof(a));
  6.     }

a) 10
b) 13
c) Run time error
d) 40
Answer: d
Clarification: If the system is 32-bit system, then the size of pointer will be 4 bytes. For such a system, the size of array a will be 4×10 = 40 bytes. The size of pointer is 8 bytes on a 64 bit system. For the given array a of 10 elements, it will be 8×10 = 80 bytes.

7. What will be the output of the following C code on a 32-bit system?

  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         printf("%dn", sizeof(a[1]));
  6.     }

a) 6
b) 4
c) 5
d) 3
Answer: b
Clarification: Array element a[1] is storing an address of character pointer. For a 32-bit systems its 4 bytes and for a 64-bit system, its 8 bytes.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         char *a[10] = {"hi", "hello", "how"};
  5.         int i = 0;
  6.         for (i = 0;i < 10; i++)
  7.         printf("%s", a[i]);
  8.     }

a) hi hello how Segmentation fault
b) hi hello how null
c) hey hello how Segmentation fault
d) hi hello how followed by 7 nulls
Answer: d
Clarification: None.

250+ TOP MCQs on Pointer to Structures and Answers

C quiz on “Pointer to Structures”. 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 “Pointer to Structures” along with answers, explanations and/or solutions:

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

  1.     #include 
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  10.         struct p *ptr1 = p1;
  11.         int x = (sizeof(p1) / 3);
  12.         if (x == sizeof(int) + sizeof(char))
  13.             printf("%dn", ptr1->x);
  14.         else
  15.             printf("falsen");
  16.     }

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

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

  1.     #include 
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  10.         struct p *ptr1 = p1;
  11.         int x = (sizeof(p1) / sizeof(ptr1));
  12.         if (x == 1)
  13.             printf("%dn", ptr1->x);
  14.         else
  15.             printf("falsen");
  16.     }

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

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

  1.     #include 
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     typedef struct p* q*;
  8.     int main()
  9.     {
  10.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  11.         q ptr1 = p1;
  12.         printf("%dn", ptr1->x);
  13.     }

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

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

  1.     #include 
  2.     struct p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     void foo(struct p* );
  8.     int main()
  9.     {
  10.         typedef struct p* q;
  11.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  12.         foo(p1);
  13.     }
  14.     void foo(struct p* p1)
  15.     {
  16.         q ptr1 = p1;
  17.         printf("%dn", ptr1->x);
  18.     }

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

5. Which of the following is an incorrect syntax for pointer to structure?

(Assuming struct temp{int b;}*my_struct;)

a) *my_struct.b = 10;
b) (*my_struct).b = 10;
c) my_struct->b = 10;
d) Both *my_struct.b = 10; and (*my_struct).b = 10;
Answer: a
Clarification: None.

6. Which of the following is an incorrect syntax to pass by reference a member of a structure in a function?

(Assume: struct temp{int a;}s;)

a) func(&s.a);
b) func(&(s).a);
c) func(&(s.a));
d) none of the mentioned
Answer: d
Clarification: None.

7. Which of the following structure declaration doesn’t require pass-by-reference?
a)

   struct{int a;}s;
   main(){}

b)

   struct temp{int a;};
   main(){
       struct temp s;
   }

c)

   struct temp{int a;};
   main(){}
   struct temp s;

d) none of the mentioned
Answer: d
Clarification: None.

8. Which option is not possible for the following function call?

  1. func(&s.a); //where s is a variable of type struct and a is the member of the struct.

a) Compiler can access entire structure from the function
b) Individual member’s address can be displayed in structure
c) Individual member can be passed by reference in a function
d) None of the mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  2.     struct temp
  3.     {
  4.         int a;
  5.     } s;
  6.     void change(struct temp);
  7.     main()
  8.     {
  9.         s.a = 10;
  10.         change(s);
  11.         printf("%dn", s.a);
  12.     }
  13.     void change(struct temp s)
  14.     {
  15.         s.a = 1;
  16.     }

a) Output will be 1
b) Output will be 10
c) Output varies with machine
d) Compile time error
Answer: b
Clarification: None.

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

  1.  #include 
  2.     struct p
  3.      {
  4.         int x;
  5.         int y;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p1[] = {1, 92, 3, 94, 5, 96};
  10.         struct p *ptr1 = p1;
  11.         int x = (sizeof(p1) / 5);
  12.         if (x == 3)
  13.             printf("%d %dn", ptr1->x, (ptr1 + x - 1)->x);
  14.         else
  15.             printf("falsen");
  16.     }

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