250+ TOP MCQs on Conditional Expressions and Answers

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

Here is a listing of C Objective Questions on “Conditional Expressions” 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 k = 8;
  5.         int m = 7;
  6.         k < m ? k++ : m = k;
  7.         printf("%d", k);
  8.     }

a) 7
b) 8
c) Compile time error
d) Run time error
Answer: c
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k = k + 1 : m = m + 1;
  7.         printf("%d", k);
  8.     }

a) Compile time error
b) 9
c) 8
d) Run time error
Answer: a
Clarification: None.

3. What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)

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

4. What will be the data type of the following expression? (Initial data type: a = int, var1 = double, var2 = float)

expression (a < 50)? var1 : var2;

a) int
b) float
c) double
d) Cannot be determined
Answer: c
Clarification: None.

5. Which expression has to be present in the following?

exp1 ? exp2 : exp3;

a) exp1
b) exp2
c) exp3
d) all of the mentioned
Answer: d
Clarification: None.

6. What will be the final value of c in the following C code snippet? (Initial values: a = 1, b = 2, c = 1)

a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
Answer: c
Clarification: None.

7. The following C code can be rewritten as _______

a)

    if (!n)c = b;
    else c = a;

b)

    if (n <;= 0)c = b;
    else c = a;

c)

    if (n > 0)c = a;
    else c = b;

d) All of the mentioned
Answer: a
Clarification: None.

250+ TOP MCQs on Goto & Labels and Answers

tough C programming questions on “Goto & Labels”. 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 tough 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.     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) Compilation error
c) 1 2 4
d) 1 3 4
Answer: a
Clarification: None.

2. 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) Compilation error
b) 1 2 3
c) 1 2
d) 1 3
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.     }
  8.     void foo()
  9.     {
  10.         l1 : printf("3 ", 3);
  11.     }

a) 1 2 3
b) 1 3
c) 1 3 2
d) Compilation error
Answer: d
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.         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) Compilation error
c) Loop Loop Loop Loop
d) Infinite Loop
Answer: d
Clarification: None.

5. 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) Compilation error
c) loop loop loop loop
d) Infinite 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, 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) compilation error
c) oop loop loop loop
d) infinite loop
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.         if (i == 0)
  6.         {
  7.             goto label;
  8.         }
  9.         label: printf("Hello");
  10.     }

a) Nothing
b) Error
c) Infinite Hello
d) Hello
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0, k;
  5.         if (i == 0)
  6.             goto label;
  7.             for (k = 0;k < 3; k++)
  8.             {
  9.                 printf("hin");
  10.                 label: k = printf("%03d", i);
  11.             }
  12.     }

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

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

  1.     #include 
  2.     void main()
  3.     {
  4.         int i = 0, k;
  5.         label: printf("%d", i);
  6.         if (i == 0)
  7.             goto label;
  8.     }

a) 0
b) Infinite 0
c) Nothing
d) Error
Answer: b
Clarification: None.

250+ TOP MCQs on C-Preprocessor and Answers

C questions and puzzles on “C Preprocessor”. 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 “C Preprocessor” along with answers, explanations and/or solutions:

1. Property which allows to produce different executable for different platforms in C is called?
a) File inclusion
b) Selective inclusion
c) Conditional compilation
d) Recursive macros
Answer: c
Clarification: Conditional compilation is the preprocessor facility to produce a different executable.

2. What is #include ?
a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
Answer: a
Clarification: None.

3. C preprocessors can have compiler specific features.
a) True
b) False
c) Depends on the standard
d) Depends on the platform
Answer: a
Clarification: #pragma is compiler specific feature.

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

  1. #include 
  2. #define foo(m, n) m * n = 10
  3. int main()
  4. {
  5.     printf("in mainn");
  6. }

a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
Answer: a
Clarification: Preprocessor just replaces whatever is given compiler then checks for error at the replaced part of the code. Here it is not replaced anywhere.
Output:
$ cc pgm1.c
$ a.out
in main

5. C preprocessor is conceptually the first step during compilation.
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Clarification: None.

6. Preprocessor feature that supply line numbers and filenames to compiler is called?
a) Selective inclusion
b) macro substitution
c) Concatenation
d) Line control
Answer: d
Clarification: None.

7. #include are _______ files and #include “somefile.h” ________ files.
a) Library, Library
b) Library, user-created header
c) User-created header, library
d) They can include all types of file
Answer: d
Clarification: Both of these statement can be used to select any file.

8. What is a preprocessor?
a) That processes its input data to produce output that is used as input to another program
b) That is nothing but a loader
c) That links various source files
d) All of the mentioned
Answer: a
Clarification: A preprocessor is a program that processes its input data to produce output that is used as input to another program.

250+ TOP MCQs on Character Pointers and Functions and Answers

C Objective Questions on “Character Pointers and Functions”. 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 “Character Pointers and Functions” 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, worldn";
  5.         char *strc = "good morningn";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello, world
b) Crash/segmentation fault
c) Undefined behaviour
d) Run time error
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 strc[] = "good morning indian";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello world
b) hello worldg india
c) Compile time error
d) Undefined behaviour
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello, world!!n";
  5.         char strc[] = "good morningn";
  6.         strcpy(strc, str);
  7.         printf("%sn", strc);
  8.         return 0;
  9.     }

a) hello, world!!
b) Compile time error
c) Undefined behaviour
d) Segmenation fault
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.         str[5] = '.';
  6.         printf("%sn", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: d
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char str[] = "hello, world";
  5.         str[5] = '.';
  6.         printf("%sn", str);
  7.         return 0;
  8.     }

a) hello. world
b) hello, world
c) Compile error
d) Segmentation fault
Answer: a
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         char *str = "hello world";
  5.         char strary[] = "hello world";
  6.         printf("%d %dn", sizeof(str), sizeof(strary));
  7.         return 0;
  8.     }

a) 11 11
b) 12 12
c) 4 12
d) 4 11
Answer: c
Clarification: None.

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

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

a) 11 11
b) 12 11
c) 11 12
d) x 11 where x can be any positive integer.
Answer: a
Clarification: None.

8. 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.         printf("%cn", *k);
  7.     }
  8.     void main()
  9.     {
  10.         char s[] = "hello";
  11.         f(s);
  12.     }

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

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

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

a) hello
b) Run time error
c) Nothing
d) h
Answer: a
Clarification: None.

250+ TOP MCQs on Basics of Structures and Answers

online C quiz on “Basics of Structures”. One shall practice these online 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 online C quiz on “Basics of Structures” along with answers, explanations and/or solutions:

1. Which of the following are themselves a collection of different data types?
a) string
b) structures
c) char
d) all of the mentioned
Answer: b
Clarification: None.

2. User-defined data type can be derived by___________
a) struct
b) enum
c) typedef
d) all of the mentioned
Answer: d
Clarification: None.

3. Which operator connects the structure name to its member name?
a) –
b) <-
c) .
d) Both <- and .
Answer: c
Clarification: None.

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

5. Which of the following structure declaration will throw an error?
a)

b)

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

c)

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

d) None of the mentioned
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. Can the following C code be compiled successfully?

  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) Yes
b) No
c) Depends on the standard
d) Depends on the platform
Answer: c
Clarification: None.

250+ TOP MCQs on Bit-fields and Answers

C programming Objective Questions on “Bit-fields”. 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 programming Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

1. What is the correct syntax to initialize bit-fields in an structure?
a)

    struct temp
    {
        unsigned int a : 1;
    }s;

b)

    struct temp
    {
        unsigned int a = 1;
    }s;

c)

    struct temp
    {
        unsigned float a : 1;
    }s;

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

2. Which of the following data types are accepted while declaring bit-fields?
a) char
b) float
c) double
d) none of the mentioned
Answer: a
Clarification: None.

3. Which of the following reduces the size of a structure?
a) union
b) bit-fields
c) malloc
d) none of the mentioned
Answer: b
Clarification: None.

4. For what minimum value of x in a 32-bit Linux OS would make the size of s equal to 8 bytes?

  1.     struct temp
  2.     {
  3.         int a : 13;
  4.         int b : 8;
  5.         int c : x;
  6.     }s;

a) 4
b) 8
c) 12
d) 32
Answer: c
Clarification: None.

5. Calculate the % of memory saved when bit-fields are used for the following C structure as compared to with-out use of bit-fields for the same structure? (Assuming size of int = 4)

  1.     struct temp
  2.     {
  3.         int a : 1;
  4.         int b : 2;
  5.         int c : 4;
  6.         int d : 4;
  7.     }s;

a) 25%
b) 33.3%
c) 50%
d) 75%
Answer: d
Clarification: None.

6. In the following declaration of bit-fields, the constant-expression specifies __________

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression

a) The width of the field in bits
b) Nothing
c) The width of the field in bytes
d) Error
Answer: a
Clarification: None.

7. In the following declaration of bit-fields, the constant-expression must be __________

    struct-declarator:
    declarator
    type-specifier declarator opt : constant-expression

a) Any type
b) Nothing
c) Integer value
d) Nonnegative integer value
Answer: d
Clarification: None.

8. Which of the following is not allowed?
a) Arrays of bit fields
b) Pointers to bit fields
c) Functions returning bit fields
d) None of the mentioned
Answer: d
Clarification: None.

9. Bit fields can only be declared as part of a structure.
a) false
b) true
c) Nothing
d) Varies
Answer: b
Clarification: None.

10. What is the order for the following C declarations?

    short a : 17;
    int long y : 33;

a) Legal, legal
b) Legal, illegal
c) Illegal, illegal
d) Illegal, legal
Answer: c
Clarification: None.