250+ TOP MCQs on Goto & Labels and Answers

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

Here is a listing of C programming questions on “Goto & Labels” 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 = 5, k;
  5.         if (i == 0)
  6.             goto label;
  7.             label: printf("%d", i);
  8.             printf("Hey");
  9.     }

a) 5
b) Hey
c) 5 Hey
d) Nothing
Answer: c
Clarification: None.

2. goto can be used to jump from main() to within a function.
a) true
b) false
c) depends
d) varies
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         goto l1;
  6.         printf("%d ", 2);
  7.         l1:goto l2;
  8.         printf("%d ", 3);
  9.         l2:printf("%d ", 4);
  10.    }

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

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

  1.     #include 
  2.     int main()
  3.     {
  4.         printf("%d ", 1);
  5.         l1:l2:
  6.         printf("%d ", 2);
  7.         printf("%dn", 3);
  8.     }

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

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

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

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

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

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

a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: d
Clarification: None.

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

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

a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: b
Clarification: None.

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

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

a) loop loop
b) Compile time error
c) loop loop loop loop
d) Infinite loop
Answer: a
Clarification: None.

250+ TOP MCQs on C-Preprocessor and Answers

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

1. Which of the following are C preprocessors?
a) #ifdef
b) #define
c) #endif
d) all of the mentioned
Answer: d
Clarification: None.

2. #include statement must be written __________
a) Before main()
b) Before any scanf/printf
c) After main()
d) It can be written anywhere
Answer: b
Clarification: Using these directives before main() improves readability.

3. #pragma exit is primarily used for?
a) Checking memory leaks after exiting the program
b) Informing Operating System that program has terminated
c) Running a function at exiting the program
d) No such preprocessor exist
Answer: c
Clarification: It is primarily used for running a function upon exiting the program.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int one = 1, two = 2;
  5.         #ifdef next
  6.         one = 2;
  7.         two = 1;
  8.         #endif
  9.         printf("%d, %d", one, two);
  10.     }

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

5. The C-preprocessors are specified with _________symbol.
a) #
b) $
c) ” ”
d) &
Answer: a
Clarification: The C-preprocessors are specified with # symbol.

6. What is #include directive?
a) Tells the preprocessor to grab the text of a file and place it directly into the current file
b) Statements are not typically placed at the top of a program
c) All of the mentioned
d) None of the mentioned
Answer: a
Clarification: The #include directive tells the preprocessor to grab the text of a file and place it directly into the current file and are statements are typically placed at the top of a program.

7. The preprocessor provides the ability for _______________
a) The inclusion of header files
b) The inclusion of macro expansions
c) Conditional compilation and line control
d) All of the mentioned
Answer: d
Clarification: The preprocessor provides the ability for the inclusion of header files, macro expansions, conditional compilation, and line control.

8. If #include is used with file name in angular brackets.
a) The file is searched for in the standard compiler include paths
b) The search path is expanded to include the current source directory
c) The search path will expand
d) None of the mentioned
Answer: a
Clarification: With the #include, if the filename is enclosed within angle brackets, the file is searched for in the standard compiler include paths.

250+ TOP MCQs on Character Pointers and Functions and Answers

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

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

1. Comment on the output of the following C code.

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "This" //Line 1
  5.         char *ptr = "Programn"; //Line 2
  6.         str = ptr; //Line 3
  7.         printf("%s, %sn", str, ptr); //Line 4
  8.     }

a) Memory holding “this” is cleared at line 3
b) Memory holding “this” loses its reference at line 3
c) You cannot assign pointer like in Line 3
d) Output will be This, Program
Answer: b
Clarification: None.

2. What type of initialization is needed for the segment “ptr[3] = ‘3’;” to work?
a) char *ptr = “Hello!”;
b) char ptr[] = “Hello!”;
c) both char *ptr = “Hello!”; and char ptr[] = “Hello!”;
d) none of the mentioned
Answer: b
Clarification: None.

3. What is the syntax for constant pointer to address (i.e., fixed pointer address)?
a) const *
b) * const
c) const *
d) none of the mentioned
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int add(int a, int b)
  3.     {
  4.         return a + b;
  5.     }
  6.     int main()
  7.     {
  8.         int (*fn_ptr)(int, int);
  9.         fn_ptr = add;
  10.         printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));
  11.     }

a) Compile time error, declaration of a function inside main
b) Compile time error, no definition of function fn_ptr
c) Compile time error, illegal application of statement fn_ptr = add
d) No Run time error, output is 5
Answer: d
Clarification: None.

5. What is the correct way to declare and assign a function pointer?

(Assuming the function to be assigned is "int multi(int, int);")

a) int (*fn_ptr)(int, int) = multi;
b) int *fn_ptr(int, int) = multi;
c) int *fn_ptr(int, int) = &multi;
d) none of the mentioned
Answer: a
Clarification: None.

6. Calling a function f with a an array variable a[3] where a is an array, is equivalent to __________
a) f(a[3])
b) f(*(a + 3))
c) f(3[a])
d) all of the mentioned
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void f(char *k)
  3.     {
  4.         k++;
  5.         k[2] = 'm';
  6.     }
  7.     void main()
  8.     {
  9.         char s[] = "hello";
  10.         f(s);
  11.         printf("%cn", *s);
  12.     }

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

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

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

a) Compile time error
b) h
c) e
d) o
Answer: a
Clarification: None.

250+ TOP MCQs on Basics of Structures and Answers

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

Here is a listing of C multiple choice questions on “Basics of Structures” 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.         struct student
  5.         {
  6.             int no;
  7.             char name[20];
  8.         };
  9.         struct student s;
  10.         no = 8;
  11.         printf("%d", no);
  12.     }

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

2. How many bytes in memory taken by the following C structure?

  1.     #include 
  2.     struct test
  3.     {
  4.         int k;
  5.         char c;
  6.     };

a) Multiple of integer size
b) integer size+character size
c) Depends on the platform
d) Multiple of word size
Answer: a
Clarification: None.

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

  1.     #include 
  2.     struct
  3.     {
  4.         int k;
  5.         char c;
  6.     };
  7.     int main()
  8.     {
  9.         struct p;
  10.         p.k = 10;
  11.         printf("%dn", p.k);
  12.     }

a) Compile time error
b) 10
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
  3.     {
  4.         int k;
  5.         char c;
  6.     } p;
  7.     int p = 10;
  8.     int main()
  9.     {
  10.         p.k = 10;
  11.         printf("%d %dn", p.k, p);
  12.     }

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

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

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

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

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

  1.     #include 
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int p = 10;
  9.     int main()
  10.     {
  11.         struct p x = {1, 97};
  12.         printf("%f %dn", x.f, p);
  13.     }

a) Compile time error
b) 0.000000 10
c) Somegarbage value 10
d) 0 10
Answer: b
Clarification: None.

7. What will be the output of the following C code according to C99 standard?

  1.     #include 
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97, .f = 3, .k = 1};
  11.         printf("%fn", x.f);
  12.     }

a) 3.000000
b) Compile time error
c) Undefined behaviour
d) 1.000000
Answer: a
Clarification: None.

8. What will be the output of the following C code according to C99 standard?

  1.     #include 
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97, .k = 1, 3};
  11.         printf("%f n", x.f);
  12.     }

a) 3.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour
Answer: b
Clarification: None.

9. What will be the output of the following C code according to C99 standard?

  1.     #include 
  2.     struct p
  3.     {
  4.         int k;
  5.         char c;
  6.         float f;
  7.     };
  8.     int main()
  9.     {
  10.         struct p x = {.c = 97};
  11.         printf("%fn", x.f);
  12.     }

a) 0.000000
b) Somegarbagevalue
c) Compile time error
d) None of the mentioned
Answer: a
Clarification: None.

250+ TOP MCQs on Bit-fields and Answers

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

Here is a listing of C programming questions on “Bit-Fields” 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.         char x : 2;
  5.         int y : 2;
  6.     };
  7.     int main()
  8.     {
  9.         struct p p;
  10.         p.x = 2;
  11.         p.y = 1;
  12.         p.x = p.x & p.y;
  13.         printf("%dn", p.x);
  14.     }

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

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

  1.     #include 
  2.     union u
  3.     {
  4.         struct p
  5.         {
  6.             unsigned char x : 2;
  7.             unsigned int y : 2;
  8.         };
  9.         int x;
  10.     };
  11.     int main()
  12.     {
  13.         union u u;
  14.         u.p.x = 2;
  15.         printf("%dn", u.p.x);
  16.     }

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

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

  1.     #include 
  2.     union u
  3.     {
  4.         struct
  5.         {
  6.             unsigned char x : 2;
  7.             unsigned int y : 2;
  8.         }p;
  9.         int x;
  10.     };
  11.     int main()
  12.     {
  13.         union u u;
  14.         u.p.x = 2;
  15.         printf("%dn", u.p.x);
  16.     }

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

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

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

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

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

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

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

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

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

a) Compile time error
b) 2
c) Undefined behaviour
d) None of the mentioned
Answer: a
Clarification: None.

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

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

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

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

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

a) 0
b) 4
c) Depends on the compiler
d) 2
Answer: a
Clarification: None.

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

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

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

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

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

a) 1
b) 2
c) 0
d) Depends on the compiler
Answer: c
Clarification: None.

250+ TOP MCQs on Character Class Testing & Conversions and Answers

C test on “Character Class Testing & Conversions”. 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 C test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C test questions on “Character Class Testing & Conversions” along with answers, explanations and/or solutions:

1. Which of the following library function is not case-sensitive?
a) toupper()
b) tolower()
c) isdigit()
d) all of the mentioned
Answer: c
Clarification: None.

2. The following C expression can be substituted for?

 if (isalpha(c) && isdigit(c))

a) if (isalnum(c))
b) if (isalphanum(c))
c) if (isalphanumeric(c))
d) none of the mentioned
Answer: d
Clarification: None.

3. Which of the following will return a non-zero value when checked with isspace(c)?
a) blank
b) newline
c) return
d) all of the mentioned
Answer: d
Clarification: None.

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

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         char i = 9;
  6.         if (isdigit(i))
  7.             printf("digitn");
  8.         else
  9.             printf("not digitn");
  10.             return 0;
  11.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: b
Clarification: None.

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

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         int i = 9;
  6.         if (isdigit(i))
  7.             printf("digitn");
  8.         else
  9.             printf("not digitn");
  10.             return 0;
  11.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char i = '9';
  5.         if (isdigit(i))
  6.             printf("digitn");
  7.         else
  8.             printf("not digitn");
  9.             return 0;
  10.     }

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned
Answer: a
Clarification: None.

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

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         if (isspace(i))
  7.             printf("spacen");
  8.         else
  9.             printf("not spacen");
  10.             return 0;
  11.     }

a) Compile time error
b) space
c) not space
d) None of the mentioned
Answer: c
Clarification: The value of variable i is 0 which is the NULL character in ASCII. Hence, the output will be printed as “not space”.

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

  1.     #include 
  2.     #include 
  3.     int main()
  4.     {
  5.         int i = 32;
  6.         if (isspace(i))
  7.             printf("spacen");
  8.         else
  9.             printf("not spacen");
  10.             return 0;
  11.     }

a) Compile time error
b) space
c) not space
d) None of the mentioned
Answer: b
Clarification: The ASCII value of space character is 32. Since the variable i stores 32, the output will be printed as “space”.