250+ TOP MCQs on Break and Continue and Answers

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

Here is a listing of basic C questions on “Break and Continue” 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 i = 0;
  5.         if (i == 0)
  6.         {
  7.             printf("Hello");
  8.             continue;
  9.         }
  10.     }

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

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

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

a) Hello is printed infinite times
b) Hello
c) Varies
d) Compile time error
Answer: d
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.         {
  7.             i++;
  8.             if (i == 2)
  9.                 continue;
  10.                 printf("In while loop ");
  11.         } while (i < 2);
  12.         printf("%dn", i);
  13.     }

a) In while loop 2
b) In while loop in while loop 3
c) In while loop 3
d) Infinite loop
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0, j = 0;
  5.         for (i; i < 2; i++){
  6.             for (j = 0; j < 3; j++)
  7.             {
  8.                 printf("1n");
  9.                 break;
  10.             }
  11.             printf("2n");
  12.         }
  13.         printf("after loopn");
  14.     }

a)

b)

c)

d)

View Answer

Answer: c
Clarification: None.

 
 

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         while (i < 2)
  6.         {
  7.             if (i == 1)
  8.                 break;
  9.                 i++;
  10.                 if (i == 1)
  11.                     continue;
  12.                     printf("In while loopn");
  13.         }
  14.         printf("After loopn");
  15.     }

a)

   In while loop
   After loop

b) After loop
c)

   In while loop
   In while loop
   After loop

d) In while loop
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         char c = 'a';
  6.         while (i < 2)
  7.         {
  8.             i++;
  9.             switch (c) 
  10.             {
  11.                case 'a':
  12.                    printf("%c ", c);
  13.                    break;
  14.                    break;
  15.             }
  16.         }
  17.         printf("after loopn");
  18.     }

a) a after loop
b) a a after loop
c) after loop
d) error
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("before continue ");
  5.         continue;
  6.         printf("after continuen");
  7.     }

a) Before continue after continue
b) Before continue
c) After continue
d) Compile time error
Answer: d
Clarification: None.

250+ TOP MCQs on Automatic Variables and Answers

C helps anyone preparing for Samsung and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Samsung interviews on C Programming language.

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

1. Automatic variables are _________
a) Declared within the scope of a block, usually a function
b) Declared outside all functions
c) Declared with the auto keyword
d) Declared within the keyword extern
Answer: a
Clarification: None.

2. What is the scope of an automatic variable?
a) Exist only within that scope in which it is declared
b) Cease to exist after the block is exited
c) Exist only within that scope in which it is declared & exist after the block is exited
d) All of the mentioned
Answer: c
Clarification: None.

3. Automatic variables are allocated memory in ___________
a) heap
b) Data segment
c) Code segment
d) stack
Answer: d
Clarification: None.

4. What will be the x in the following C code?

  1.     #include 
  2.     void main()
  3.     {
  4.         int x;
  5.     }

a) automatic variable
b) static variable
c) register variable
d) global variable
Answer: a
Clarification: None.

5. Automatic variables are initialized to ___________
a) Zero
b) Junk value
c) Nothing
d) Both Zero & Junk value
Answer: b
Clarification: None.

6. Which of the following storage class supports char data type?
a) register
b) static
c) auto
d) all of the mentioned
Answer: d
Clarification: None.

7. A local variable declaration with no storage class specified is by default _________
a) auto
b) extern
c) static
d) register
Answer: a
Clarification: None.

contest

250+ TOP MCQs on Address Arithmetic and Answers

C helps anyone preparing for Tech Mahindra and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear Tech Mahindra interviews on C Programming language.

Here is a listing of C programming questions on “Address Arithmetic” 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.         char *s = "hello";
  5.         char *p = s * 3;
  6.         printf("%ct%c", *p, s[1]);
  7.     }

a) h e
b) l e
c) Compile time error
d) l h
Answer: c
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 + 2;
  6.         printf("%ct%c", *p, s[1]);
  7.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         void *p;
  5.         int a[4] = {1, 2, 3, 8};
  6.         p = &a[3];
  7.         int *ptr = &a[2];
  8.         int n = p - ptr;
  9.         printf("%dn", n);
  10.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         void *p;
  5.         int a[4] = {1, 2, 3, 4};
  6.         p = &a[3];
  7.         int *ptr = &a[2];
  8.         int n = (int*)p - ptr;
  9.         printf("%dn", n);
  10.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         int b[4] = {1, 2, 3, 4};
  6.         int n = &b[3] - &a[2];
  7.         printf("%dn", n);
  8.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         int *p = &a[1];
  6.         int *ptr = &a[2];
  7.         ptr = ptr * 1;
  8.         printf("%dn", *ptr);
  9.     }

a) 2
b) 1
c) Compile time error
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 a[4] = {1, 2, 3, 4};
  5.         int *ptr  =  &a[2];
  6.         float n = 1;
  7.         ptr = ptr + n;
  8.         printf("%dn", *ptr);
  9.     }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int a[4] = {1, 2, 3, 4};
  5.         void *p = &a[1];
  6.         void *ptr = &a[2];
  7.         int n = 1;
  8.         n = ptr - p;
  9.         printf("%dn", n);
  10.     }

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

250+ TOP MCQs on Complicated Declarations and Answers

C helps anyone preparing for EMC and other companies C interviews. One should practice these Objective Questions and answers continuously for 2-3 months to clear EMC interviews on C Programming language.

Here is a listing of C multiple choice questions on “Complicated Declarations” along with answers, explanations and/or solutions:

1. Read the following expression?

a) ptr is pointer to int that converts its type to void
b) ptr is pointer to function passing int returning void
c) ptr is pointer to void that converts its type to int
d) ptr is pointer to function passing void returning int
Answer: b
Clarification: None.

2. Which of the following expression is true for the following C statement?

ptr is array with 3 elements of pointer to function returning pointer of int

a) int **ptr[3]();
b) int *(*ptr[3])();
c) int (*(*ptr[3])());
d) None of the mentioned
Answer: b
Clarification: None.

3. What makes the following declaration denote?

a) ptr is a function pointer that returns pointer to int type
b) ptr is a pointer to an int pointer
c) ptr is a pointer to pointer to type int
d) none of the mentioned
Answer: b
Clarification: None.

4. What makes the following declaration denote?

a) str is an array of 5 element pointer to type char
b) str is a pointer to an array of 5 elements
c) str is a function pointer of 5 elements returning char
d) none of the mentioned
Answer: a
Clarification: None.

5. Comment on the following declaration.

    int (*ptr)(); // i)
    char *ptr[]; // ii)

a) Both i) and ii) and cannot exist due to same name
b) i) is legal, ii) is illegal
c) i) is illegal, ii) is legal
d) Both i) and ii) will work legal and flawlessly
Answer: d
Clarification: None.

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     }
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no = 5;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     struct student
  3.     {
  4.         int no;
  5.         char name[20];
  6.     };
  7.     void main()
  8.     {
  9.         student s;
  10.         s.no = 8;
  11.         printf("hello");
  12.     }

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

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

  1.     #include 
  2.     void main()
  3.     {
  4.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         s.no = 8;
  11.         printf("%d", s.no);
  12.     }

a) Nothing
b) Compile time error
c) Junk
d) 8
Answer: d
Clarification: None.

10. Is the below declaration legal?

a) True
b) False
c) Undefined behaviour
d) Depends on the standard
Answer: b
Clarification: None.

250+ TOP MCQs on Unions and Answers

C Objective Questions on “Unions”. One shall practice these Objective 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 C Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

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

  1.     #include 
  2.     union
  3.     {
  4.         int x;
  5.         char y;
  6.     }p;
  7.     int main()
  8.     {
  9.         p.x = 10;
  10.         printf("%dn", sizeof(p));
  11.     }

a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(int)
Answer: d
Clarification: None.

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

  1.     #include 
  2.     union
  3.     {
  4.         int x;
  5.         char y;
  6.     }p;
  7.     int main()
  8.     {
  9.         p.y = 60;
  10.         printf("%dn", sizeof(p));
  11.     }

a) Compile time error
b) sizeof(int) + sizeof(char)
c) Depends on the compiler
d) sizeof(char)
Answer: c
Clarification: None.

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

  1.     #include 
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.y = 60;
  11.         b.x = 12;
  12.         printf("%dn", p.y);
  13.     }

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

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

  1.     #include 
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     }k = {1, 97};
  7.     int main()
  8.     {
  9.         printf("%dn", k.y);
  10.     }

a) Compile time error
b) 97
c) a
d) 1
Answer: d
Clarification: None.

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

  1.     #include 
  2.     union p
  3.     {
  4.         int x;
  5.         char y;
  6.     }k = {.y = 97};
  7.     int main()
  8.     {
  9.         printf("%dn", k.y);
  10.     }

a) Compile time error
b) 97
c) a
d) Depends on the standard
Answer: b
Clarification: None.

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

  1.     #include 
  2.     union p
  3.     {
  4.         int x;
  5.         float y;
  6.     };
  7.     int main()
  8.     {
  9.         union p p, b;
  10.         p.x = 10;
  11.         printf("%fn", p.y);
  12.     }

a) Compile time error
b) Implementation dependent
c) 10.000000
d) 0.000000
Answer: b
Clarification: None.

7. Which of the following share a similarity in syntax?

1. Union, 2. Structure, 3. Arrays and 4. Pointers

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

8. What will be the output of the following C code? (Assuming size of char = 1, int = 4, double = 8)

  1.     #include 
  2.     union utemp
  3.     {
  4.         int a;
  5.         double b;
  6.         char c;
  7.     }u;
  8.     int main()
  9.     {
  10.         u.c = 'A';
  11.         u.a = 1;
  12.         printf("%d", sizeof(u));
  13.     }

a) 1
b) 4
c) 8
d) 13
Answer: c
Clarification: None.

250+ TOP MCQs on String Operations and Answers

C programming questions on “String Operations”. One shall practice these 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 C programming questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C programming questions on “String Operations” 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.         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
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world";
  5.         char str1[15] = "hello wo 9";
  6.         strcpy(str, str1);
  7.         printf("%s", str1);
  8.     }

a) Compilation error
b) Segmentation Fault
c) hello, world
d) hello, wo 9
Answer: b
Clarification: None.

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

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char *str = "hello, world";
  6.         char str1[9];
  7.         strncpy(str1, str, 9);
  8.         printf("%s %d", str1, strlen(str1));
  9.     }

a) hello, world 11
b) hello, wor 9
c) Undefined behaviour
d) Compilation error
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, worldn";
  5.         printf("%d", strlen(str));
  6.  
  7.     }

a) Compilation error
b) Undefined behaviour
c) 13
d) 11
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char str[11] = "hello";
  5.         char *str1 = "world";
  6.         strcat(str, str1);
  7.         printf("%s %d", str, str[10]);
  8.     }

a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash
Answer: a
Clarification: None.

6. Strcat() function adds null character.
a) Only if there is space
b) Always
c) Depends on the standard
d) Depends on the compiler
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char str[10] = "hello";
  5.         char *str1 = "world";
  6.         strncat(str, str1, 9);
  7.         printf("%s", str);
  8.     }

a) helloworld
b) Undefined behaviour
c) helloworl
d) hellowor
Answer: a
Clarification: None.