This section on C interview questions and answers focuses on “Variable Names”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walk-in 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 Interview questions come with the detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Variable Names” along with answers, explanations and/or solutions:

1. C99 standard guarantees uniqueness of __________ characters for internal names.
a) 31
b) 63
c) 12
d) 14

Answer: b
Explanation: ISO C99 compiler may consider only first 63 characters for internal names.

2. C99 standard guarantees uniqueness of ___________ characters for external names.
a) 31
b) 6
c) 12
d) 14

Answer: a
Explanation: ISO C99 compiler may consider only first 31 characters for external names.

3. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned

Answer: d
Explanation: None.

4. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a

Answer: c
Explanation: Variable name cannot start with a digit.

5. Why do variable names beginning with the underscore is not encouraged?
a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system

Answer: c
Explanation: None.

6. All keywords in C are in ____________
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned

Answer: a
Explanation: None.

7. Variable name resolution (number of significant characters for the uniqueness of variable) depends on ___________
a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None of the mentioned

Answer: a
Explanation: It depends on the standard to which compiler and linkers are adhering.

8. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;

Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable name, it results in an error.

9. Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length

Answer: c
Explanation: According to the syntax for C variable name, it cannot start with a digit.
This section on online C test focuses on “Increment and Decrement Operators”. 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 online test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

1. What is the difference between the following 2 codes?

  1.     
  2.      main
  3.     
  4.          d a   b  
  5.         d   a  b
  6.          d a b
  7.     
  1.     
  2.      main
  3.     
  4.          d a   b  
  5.         d   a b
  6.          d a b
  7.     

a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not

Answer: d
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          a   b   c
  5.         c  a  b
  6.          a b
  7.     

a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          a   b   d  
  5.          a  aa a  b d  d  a
  6.     

a) 15, 4, 5
b) 9, 6, 9
c) 9, 3, 5
d) Undefined (Compiler Dependent)

Answer: d
Explanation: None.

4. For which of the following, “PI++;” code will fail?
a) #define PI 3.14
b) char *PI = “A”;
c) float PI = 3.14;
d) none of the Mentioned

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          a   b  
  5.          a  
  6.         b
  7.          a b
  8.     

a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8

Answer: c
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          j  i  i
  6.          j
  7.     
Answer: b
Explanation: None.

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

  1.      
  2.      main
  3.     
  4.          i  
  5.          j  i  i
  6.          j
  7.     

a) 6
b) 5
c) 4
d) Compile time error

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          i  i  i
  6.          i
  7.     

a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point

Answer: a
Explanation: None.
This section on C programming questions and answers focuses on “If-then-else Statements”. 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 “If-then-else Statements” along with answers, explanations and/or solutions:

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

  1.     
  2.      main
  3.     
  4.          x  
  5.          x  
  6.             
  7.          x  
  8.             
  9.         
  10.             
  11.     

a) hi
b) hello
c) no
d) error

Answer: a
Explanation: None.

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

  1.     
  2.      x
  3.      main
  4.     
  5.          x
  6.             
  7.         
  8.             
  9.     

a) hi
b) how are you
c) compile time error
d) error

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          x  
  5.          
  6.             
  7.     

a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          x  
  5.          x  
  6.             
  7.         
  8.             
  9.             
  10.     

a) hi
b) how are you
c) hello
d) hihello

Answer: d
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          x  
  5.          x  
  6.             
  7.  
  8.     

a) Nothing
b) Run time error
c) Hello
d) Varies

Answer: c
Explanation: None.
  1.     
  2.      main
  3.     
  4.          ch
  5.         
  6.          ch
  7.          ch
  8.         
  9.             
  10.              
  11.              
  12.             
  13.              
  14.              
  15.         
  16.     
Answer: a
Explanation: None.

7. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

  1.     
  2.      main
  3.     
  4.          ch
  5.         
  6.          ch
  7.          ch
  8.         
  9.             
  10.               
  11.               
  12.             
  13.               
  14.               
  15.         
  16.     

a) 1
b) 2
c) Compile time error
d) No Compile time error

Answer: c
Explanation: None.

8. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

  1.     
  2.      main
  3.     
  4.          ch
  5.         
  6.          ch
  7.          ch
  8.         
  9.             
  10.               
  11.            
  12.               
  13.         
  14.     

a) 1
b) 2
c) 1 2
d) Run time error

Answer: c
Explanation: None.

9. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)

  1.     
  2.      main
  3.     
  4.          ch
  5.         
  6.          ch
  7.          ch
  8.         
  9.             
  10.               
  11.               
  12.               
  13.            
  14.               
  15.         
  16.     

a) 1
b) Hi 2
c) Run time error
d) 2

Answer: d
Explanation: None.

10. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

  1.     
  2.      main
  3.     
  4.          ch
  5.         
  6.          ch
  7.          ch ch  
  8.         
  9.             
  10.               
  11.               
  12.             
  13.               
  14.               
  15.         
  16.     

a) 1
b) 2
c) 3
d) Run time error

Answer: b
Explanation: None.
This section on online C test focuses on “While Loops”. 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 online C test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

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

  1.     
  2.      main
  3.     
  4.          
  5.             
  6.         
  7.     

a) In while loop after loop
b) After loop
c) Compile time error
d) Infinite loop

Answer: c
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.         
  5.             
  6.          
  7.             
  8.     

a) In while loop
b)

   In while loop
   after loop

c) After loop
d) Infinite loop

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          
  6.             i
  7.             
  8.           i  
  9.     

a)

   In while loop
   In while loop
   In while loop

b)

   In while loop
   In while loop

c) Depends on the compiler
d) Compile time error

Answer: a
Explanation: None.

4. How many times i value is checked in the following C code?

  1.     
  2.      main
  3.     
  4.          i  
  5.          
  6.             i
  7.             
  8.           i  
  9.     

a) 2
b) 3
c) 4
d) 1

Answer: b
Explanation: None.
  1.     
  2.      main
  3.     
  4.          i  
  5.          i  
  6.             i
  7.         
  8.     

a) 2
b) 3
c) 4
d) 1

Answer: c
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.         
  6.         
  7.             
  8.           i  
  9.     

a) Compile time error
b) Hi Hi
c) Hi
d) Varies

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          i
  6.         
  7.             
  8.         
  9.     

a) H
b) H is printed infinite times
c) Compile time error
d) Varies

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.         
  6.         
  7.             
  8.           i  
  9.     

a) Nothing
b) H is printed infinite times
c) Hello
d) Run time error

Answer: c
Explanation: None.
This section on C interview questions and answers focuses on “Basics of Functions”. One shall practice these interview 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 Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Basics of Functions” along with answers, explanations and/or solutions:

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

  1.     
  2.      main
  3.     
  4.          foo
  5.         
  6.         foo
  7.     
  8.      foo
  9.     
  10.         
  11.     

a) 1 2
b) Compile time error
c) 1 2 1 2
d) Depends on the compiler

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          foo f
  5.         f
  6.     
  7.      foo
  8.     
  9.         
  10.     
  11.      f
  12.     
  13.         
  14.         foo
  15.     

a) Compile time error as foo is local to main
b) 1 2
c) 2 1
d) Compile time error due to declaration of functions inside main

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          foo
  5.          f
  6.         
  7.             foo
  8.         
  9.         f
  10.     
  11.      foo
  12.     
  13.         
  14.     

a) 2 2
b) 2
c) Compile time error
d) Depends on the compiler

Answer: d
Explanation: Even though the answer is 2, this code will compile fine only with gcc. GNU C supports nesting of functions in C as a language extension whereas standard C compiler doesn’t.

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

  1.     
  2.      foo
  3.      main
  4.     
  5.          foo
  6.         foo
  7.          
  8.     
  9.      foo
  10.     
  11.         
  12.     

a) Compile time error
b) 2
c) Depends on the compiler
d) Depends on the standard

Answer: b
Explanation: None.

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

  1.     
  2.      foo
  3.      main
  4.     
  5.          foo
  6.         foo
  7.          
  8.     
  9.      foo i
  10.     
  11.         
  12.     

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: a
Explanation: None.
  1.     
  2.      foo
  3.      main
  4.     
  5.          foo
  6.         foo
  7.          
  8.     
  9.      foo
  10.     
  11.         
  12.     

a) 2
b) Compile time error
c) Depends on the compiler
d) Depends on the standard

Answer: b
Explanation: None.

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

  1.     
  2.      m
  3.     
  4.         
  5.     
  6.      main
  7.     
  8.         m
  9.     

a) hi
b) Run time error
c) Nothing
d) Varies

Answer: a
Explanation: None.

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

  1.     
  2.      m
  3.      n
  4.     
  5.         m
  6.     
  7.      main
  8.     
  9.          m
  10.         
  11.             
  12.         
  13.     

a) hi
b) Compile time error
c) Nothing
d) Varies

Answer: b
Explanation: None.
Sanfoundry’s 1000+ MCQs on C helps anyone preparing for placement in Samsung and other companies. Anyone looking for Samsung placement papers should practice these 1000+ questions continuously for 2-3 months, thereby ensuring a top position in placements.

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

1. When compiler accepts the request to use the variable as a register?
a) It is stored in CPU
b) It is stored in cache memory
c) It is stored in main memory
d) It is stored in secondary memory

Answer: a
Explanation: None.

2. Which data type can be stored in register?
a) int
b) long
c) float
d) all of the mentioned

Answer: d
Explanation: None.

3. Which of the following operation is not possible in a register variable?
a) Reading the value into a register variable
b) Copy the value from a memory variable
c) Global declaration of register variable
d) All of the mentioned

Answer: d
Explanation: None.

4. Which among the following is the correct syntax to declare a static variable register?
a) static register a;
b) register static a;
c) Both static register a; and register static a;
d) We cannot use static and register together

Answer: d
Explanation: None.

5. Register variables reside in ________
a) stack
b) registers
c) heap
d) main memory

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.           x  
  5.          x  
  6.         
  7.             x
  8.             main
  9.         
  10.     

a) Segmentation fault
b) main is called twice
c) main is called once
d) main is called thrice

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.           x
  5.          x
  6.     

a) 0
b) Junk value
c) Compile time error
d) Nothing

Answer: b
Explanation: None.

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

  1.     
  2.       x
  3.      main
  4.     
  5.          x
  6.     

a) Varies
b) 0
c) Junk value
d) Compile time error

Answer: d
Explanation: None.
Sanfoundry’s 1000+ MCQs on C helps anyone preparing for placement in Persistent Systems and other companies. Anyone looking for Persistent placement papers should practice these 1000+ questions continuously for 2-3 months, thereby ensuring a top position in placements.

Here is a listing of C quiz on “Pointer Addresses” along with answers, explanations and/or solutions:

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

  1.     
  2.      main
  3.     
  4.          p  NULL
  5.          q  
  6.          p
  7.             
  8.         
  9.             
  10.          q
  11.             
  12.         
  13.             
  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
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          p  i
  6.          p
  7.          
  8.     

a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          p  i
  6.          p
  7.          
  8.     

a) Compile time error
b) Undefined behaviour
c) 10
d) 0.000000

Answer: d
Explanation: None.

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

  1.     
  2.      f
  3.      main
  4.     
  5.          p  f
  6.          p
  7.     
  8.      f
  9.     
  10.          j  
  11.         j  
  12.          j
  13.     

a) 10
b) Compile time error
c) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour

Answer: a
Explanation: None.

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

  1.     
  2.      f
  3.      main
  4.     
  5.          p  f
  6.          p
  7.     
  8.      f
  9.     
  10.          j  
  11.          j
  12.     

a) 10
b) Compile time error
c) Segmentation fault/runtime crash
d) Undefined behaviour

Answer: a
Explanation: We are returning address of a local variable which should not be done. In this specific instance, we are able to see the value of 10, which may not be the case if we call other functions before calling printf() in main().
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
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          ptr a  
  5.         ptr  a
  6.         ptr  
  7.          ptr a
  8.     

a) 10,10
b) 10,11
c) 11,10
d) 11,11

Answer: d
Explanation: None.

8. 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 may not change the value pointed by ptr
d) You can change the pointer as well as the value pointed by it

Answer: a
Explanation: None.
This section on C MCQs (multiple choice questions) focuses on “Multidimensional Arrays”. One shall practice these MCQs 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 multiple choice questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

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

  1.     
  2.      main
  3.     
  4.          a      
  5.          i   j  
  6.          i   i   i
  7.          j   j   j
  8.          aij
  9.     

a) 1 2 3 4 5 0
b) 1 2 3 4 5 junk
c) 1 2 3 4 5 5
d) Run time error

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          a       
  5.          i   j  
  6.          i   i   i
  7.          j   j   j
  8.          aij
  9.     

a) 1 2 3 junk 4 5
b) Compile time error
c) 1 2 3 0 4 5
d) 1 2 3 3 4 5

Answer: b
Explanation: None.

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

  1.     
  2.      f a
  3.     
  4.         a  
  5.          i   j  
  6.          i   i   i
  7.          j   j   j
  8.          aij
  9.     
  10.      main
  11.     
  12.          a  
  13.         fa
  14.     

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: a
Explanation: None.

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

  1.     
  2.      f a
  3.     
  4.         a  
  5.          i   j  
  6.          i  i   i
  7.          j  j   j
  8.          aij
  9.     
  10.      main
  11.     
  12.          a  
  13.         fa
  14.     

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: c
Explanation: None.

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

  1.     
  2.      f a
  3.     
  4.         a  
  5.          i   j  
  6.          i  i   i
  7.          j  j   j
  8.          aij
  9.     
  10.      main
  11.     
  12.          a  
  13.         fa
  14.     

a) 0 3 0 0 0 0
b) Junk 3 junk junk junk junk
c) Compile time error
d) All junk values

Answer: c
Explanation: None.
int (*a)[7];

a) An array “a” of pointers
b) A pointer “a” to an array
c) A ragged array
d) None of the mentioned

Answer: b
Explanation: None.

7. Comment on the following 2 arrays with respect to P and Q.

  1.     a1
  2.     a2
  3.    P.  of pointers
  4.    Q.  to an array

a) a1 is P, a2 is Q
b) a1 is P, a2 is P
c) a1 is Q, a2 is P
d) a1 is Q, a2 is Q

Answer: b
Explanation: None.

8. Which of the following is not possible statically in C?
a) Jagged Array
b) Rectangular Array
c) Cuboidal Array
d) Multidimensional Array

Answer: a
Explanation: None.
This section on online C quiz focuses 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
Explanation: None.

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

Answer: d
Explanation: None.

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

Answer: c
Explanation: 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
Explanation: None.

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

   struct temp{}s;
   main(){}

b)

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

c)

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

d) None of the mentioned

Answer: d
Explanation: None.

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

  1.     
  2.      student
  3.     
  4.          no
  5.          name
  6.     
  7.      main
  8.     
  9.          student s
  10.         s.  
  11.         
  12.     

a) Compile time error
b) Nothing
c) hello
d) Varies

Answer: a
Explanation: None.

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

  1.     
  2.      student
  3.     
  4.          no  
  5.          name
  6.     
  7.      main
  8.     
  9.          student s
  10.         s.  
  11.         
  12.     
Answer: b
Explanation: None.

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

  1.     
  2.      student
  3.     
  4.          no
  5.          name
  6.     
  7.      main
  8.     
  9.         student s
  10.         s.  
  11.         
  12.     

a) Nothing
b) hello
c) Compile time error
d) Varies

Answer: c
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          student
  5.         
  6.              no
  7.              name
  8.         
  9.          student s
  10.         s.  
  11.          s.
  12.     

a) Nothing
b) Compile time error
c) Junk
d) 8

Answer: d
Explanation: None.

10. Can the following C code be compiled successfully?

  1.     
  2.      p
  3.     
  4.          k
  5.          c
  6.          f
  7.     
  8.      main
  9.     
  10.          p x  .   .   .  
  11.          x.
  12.     

a) Yes
b) No
c) Depends on the standard
d) Depends on the platform

Answer: c
Explanation: None.
This section on C interview questions and answers focuses on “Self-Referential Structures”. One shall practice these interview 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 Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Self-Referential Structures” along with answers, explanations and/or solutions:

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

  1.     
  2.       p q
  3.      main
  4.     
  5.          p
  6.         
  7.              x
  8.              y
  9.             q ptr
  10.         
  11.          p p    p
  12.          p.x
  13.          
  14.     

a) Compile time error
b) 1
c) Depends on the compiler
d) None of the mentioned

Answer: a
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.           p q
  5.          p
  6.         
  7.              x
  8.              y
  9.             q ptr
  10.         
  11.          p p    p
  12.          p.x
  13.          
  14.     

a) Compile time error
b) 1
c) Depends on the compiler
d) Depends on the standard

Answer: b
Explanation: None.

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

  1.     
  2.       p q
  3.      p
  4.     
  5.          x
  6.          y
  7.         q ptr
  8.     
  9.      main
  10.     
  11.          p p    p
  12.          p.ptrx
  13.          
  14.     

a) Compile time error
b) Segmenation fault
c) Undefined behaviour
d) 1

Answer: d
Explanation: None.

4. The number of distinct nodes the following struct declaration can point to is _____________

  1.      node
  2.     
  3.          node left
  4.          node centre
  5.          node right
  6.     

a) 1
b) 2
c) 3
d) All of the mentioned

Answer: d
Explanation: None.

5. Which of the following is not possible regarding the structure variable?
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other
d) None of the mentioned

Answer: d
Explanation: None.

6. Which of the following technique is faster for travelling in binary trees?
a) Iteration
b) Recursion
c) Both Iteration and Recursion
d) Depends from compiler to compiler

Answer: b
Explanation: None.

7. Which of the following will stop the loop at the last node of a linked list in the following C code snippet?

  1.      node
  2.     
  3.          node next
  4.     

a)

     p  NULL
    
        p  pnext
    

b)

     pnext  NULL
    
        p  pnext
    

c)

     
    
        p  pnext
         p  NULL
            
    

d) All of the mentioned

Answer: b
Explanation: None.
This section on C MCQs (multiple choice questions) focuses on “Standard Input and Output”. One shall practice these MCQs 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 multiple choice questions come with detailed explanation of the answers which helps in better understanding of C concepts.

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

1. Which among the following is the odd one out?
a) printf
b) fprintf
c) putchar
d) scanf

Answer: d
Explanation: None.

2. For a typical program, the input is taken using _________
a) scanf
b) Files
c) Command-line
d) All of the mentioned

Answer: d
Explanation: None.

3. What does the following command line signify?

prog1|prog2

a) It runs prog1 first, prog2 second
b) It runs prog2 first, prog1 second
c) It runs both the programs, pipes output of prog1 to input of prog2
d) It runs both the programs, pipes output of prog2 to input of prog1

Answer: c
Explanation: None.

4. What is the default return-type of getchar()?
a) char
b) int
c) char *
d) reading character doesn’t require a return-type

Answer: b
Explanation: None.

5. What is the value of EOF?
a) -1
b) 0
c) 1
d) 10

Answer: a
Explanation: None.

6. What is the use of getchar()?
a) The next input character each time it is called
b) EOF when it encounters end of file
c) The next input character each time it is called EOF when it encounters end of file
d) None of the mentioned

Answer: c
Explanation: None.

7. Which of the following statement is true?
a) The symbolic constant EOF is defined in <stdio.h>
b) The value is -1
c) The symbolic constant EOF is defined in <stdio.h> & value is -1
d) Only value is -1

Answer: c
Explanation: None.

8. What is the return value of putchar()?
a) The character written
b) EOF if an error occurs
c) Nothing
d) Both character written & EOF if an error occurs

Answer: d
Explanation: None.
This section on C test focuses 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
Explanation: None.

2. The following C expression can be substituted for?

  c  c

a) if (isalnum(c))
b) if (isalphanum(c))
c) if (isalphanumeric(c))
d) none of the mentioned

Answer: d
Explanation: 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
Explanation: None.

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

  1.     
  2.     
  3.      main
  4.     
  5.          i  
  6.          i
  7.             
  8.         
  9.             
  10.              
  11.     

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned

Answer: b
Explanation: None.

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

  1.     
  2.     
  3.      main
  4.     
  5.          i  
  6.          i
  7.             
  8.         
  9.             
  10.              
  11.     

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned

Answer: b
Explanation: None.

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

  1.     
  2.      main
  3.     
  4.          i  
  5.          i
  6.             
  7.         
  8.             
  9.              
  10.     

a) digit
b) not digit
c) Depends on the compiler
d) None of the mentioned

Answer: a
Explanation: None.

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

  1.     
  2.     
  3.      main
  4.     
  5.          i  
  6.          i
  7.             
  8.         
  9.             
  10.              
  11.     

a) Compile time error
b) space
c) not space
d) None of the mentioned

Answer: c
Explanation: 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.     
  2.     
  3.      main
  4.     
  5.          i  
  6.          i
  7.             
  8.         
  9.             
  10.              
  11.     

a) Compile time error
b) space
c) not space
d) None of the mentioned

Answer: b
Explanation: The ASCII value of space character is 32. Since the variable i stores 32, the output will be printed as “space”.
This section on C interview questions and answers focuses on “Float Datatype”. One shall practice these interview 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 Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Float Datatype” along with answers, explanations and/or solutions:

1. How many digits are present after the decimal in float value?
a) 1
b) 3
c) 6
d) 16

Answer: c
Explanation: None.

2. Which among the following is never possible as an output for a float?
a) 3.666666
b) 3.666
c) 3
d) None of the mentioned

Answer: d
Explanation: None.

3. In a 32-bit compiler, which 2 types have the same size?
a) char and short
b) short and int
c) int and float
d) float and double

Answer: c
Explanation: None.

4. What is the size of float in a 32-bit compiler?
a) 1
b) 2
c) 4
d) 8

Answer: c
Explanation: None.

5. Loss in precision occurs for typecasting from____________
a) char to short
b) float to double
c) long to float
d) float to int

Answer: d
Explanation: None.

6. In the following C code, the union size is decided by?

  1.      temp
  2.     
  3.          a
  4.          b
  5.          c
  6.     

a) char
b) int
c) float
d) both int and float

Answer: d
Explanation: None.

7. %f access specifier is used for ________
a) Strings
b) Integral types
c) Floating type
d) All of the mentioned

Answer: c
Explanation: None.

8. Select the odd one out with respect to type?
a) char
b) int
c) long
d) float

Answer: d
Explanation: None.
This section on C programming questions and answers focuses on “Sizeof”. 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 “Sizeof” along with answers, explanations and/or solutions:

1. What is the sizeof(char) in a 32-bit C compiler?
a) 1 bit
b) 2 bits
c) 1 Byte
d) 2 Bytes

Answer: c
Explanation: None.

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

    
     

a) 1
b) 2
c) 4
d) None of the mentioned

Answer: c
Explanation: None.

3. Size of an array can be evaluated by __________

(Assuming array declaration int a[10];)

a) sizeof(a);
b) sizeof(*a);
c) sizeof(a[10]);
d) 10 * sizeof(a);

Answer: a
Explanation: None.

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

  1.     
  2.      temp
  3.     
  4.          a
  5.          b
  6.          c
  7.     t
  8.      main
  9.     
  10.          t
  11.          
  12.     

a) 1
b) 2
c) 4
d) 6

Answer: c
Explanation: None.

5. Which of the following is not an operator in C?
a) ,
b) sizeof()
c) ~
d) None of the mentioned

Answer: d
Explanation: None.

6. Which among the following has the highest precedence?
a) &
b) <<
c) sizeof()
d) &&

Answer: c
Explanation: None.

7. What is the sizeof(void) in a 32-bit C?
a) 0
b) 1
c) 2
d) 4

Answer: b
Explanation: None.

8. What type of value does sizeof return?
a) char
b) short
c) unsigned int
d) long

Answer: c
Explanation: None.

This set of C MCQs focuses on “Enums – 1”.

1. A user defined data type, which is used to assign names to integral constants is called ____________
a) Union
b) Array
c) Structure
d) Enum

Answer: d
Explanation: Enumeration (enum) is a user defined data type in C. It is used to assign names to integral constants. The names make a program easy to read and maintain.

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

 colour

    blue red yellow

main

     colour c
    cyellow
    c

a) 1
b) 2
c) 0
d) Error

Answer: c
Explanation: Enum variables are automatically assigned values if no value is specified. The compiler by default assigns values starting from 0. Therefore, in the above code, blue gets 0, red gets 1 and yellow gets 2.

3. Point out the error (if any) in the following C code?

 hello

    abc

main

     hello m
    m

a) No error
b) Error in the statement: a,b,c;
c) Error in the statement: enum hello m;
d) Error in the statement: printf(“%d”,m);

Answer: b
Explanation: In the above code, there is a semi colon given at the end of the list of variables. This results in an error. Semi colon is to be put only after the closing brace of the enum, not after the list of variables.

4. String handling functions such as strcmp(), strcpy() etc can be used with enumerated types.
a) True
b) False

Answer: b
Explanation: Enumerated types are not strings. Hence it is not possible to use string handling functions with enumerated data types.

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

 hello

    abcd

main

     hello m
    abcd

a)

    1
    99
    100
    -1

b) Error
c)

    0
    99
    100
    -1

d)

    0
    1
    2
    3
Answer: c
Explanation: We can assign values to some of the symbol names in any order. All unassigned names get the value as the value of previous name plus one.
 
 

6. Pick the incorrect statement with respect to enums.
a) Two enum symbols cannot have the same value
b) Only integer constants are allowed in enums
c) It is not possible to change the value of enum symbols
d) Enum variables are automatically assigned values if no value is specified

Answer: a
Explanation: The statement that two enum symbols cannot have the same value is incorrect. Any number of enum symbols can have the same value.

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

 sanfoundry

    ab

 sanfoundry s
main

    ab

a) 2 3
b) 0 1
c) 2 3.56
d) Error

Answer: d
Explanation: The above code will result in an error because 3.56 is not an integer constant. Only integer constants are allowed in enums.

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

 class

    abc

 class m
main

    m

a) 3
b) Same as the size of an integer
c) 3 times the size of an integer
d) Error

Answer: b
Explanation: The output will be the same as the size of an integer, that is 4 on a 32 bit platform.

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

 hiabc
 hellocde
main

     hi h
    hb
    h
     

a) 2
b) 1
c) Error
d) 0

Answer: c
Explanation: The code shown above results in an error: re-declaration of enumerator ‘c’. All enumerator constants should be unique in their scope.

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

 sanfoundry

    abc

 sanfoundry s
main

    c
    c

a) Error
b) 5
c) 6
d) 2

Answer: a
Explanation: The above code results in an error because it is not possible to modify the value of enum constants. In the above code, we have tried to increment the value of c. This results in an error.

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Typedef”.

1. Which of the following keywords is used to define an alternate name for an already existing data type?
a) default
b) volatile
c) typedef
d) static

Answer: c
Explanation: The keyword typedef is used to define an alternate name for an already existing data type. It is mostly used for used defined data types.

2. We want to create an alias name for an identifier of the type unsigned long. The alias name is: ul. The correct way to do this using the keyword typedef is ____________
a) typedef unsigned long ul;
b) unsigned long typedef ul;
c) typedef ul unsigned long;
d) ul typedef unsigned long;

Answer: a
Explanation: The syntax of the keyword typedef is: keyword <existing_name> <alias_name>;
Hence if we want to create an alias name (ul) for an identifier of type unsigned long, the correct way to do this would be: typedef unsigned long ul;

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

main

      a
    a b c d
    db
    d

a) 10
b) 16
c) 8
d) error

Answer: a
Explanation: In the code shown above, the keyword typedef is used to give an alias name (a) to an identifier of the type int. The expression on evaluation gives the answer 10. Hence the output of the code shown above is 10.

4. WWhat will be the output of the following C code? (If the name entered is: Sanfoundry)

  employee

      name
       salary
 e1
 main 

    
    e1.
    e1.

a) Sanfoundry.name
b) nSanfoundry
c) Sanfoundry
d) Error

Answer: d
Explanation: The code shown above will result in an error because we have used the data type e1 (defined using the keyword typedef) in the form of an identifier.

5. The keyword typedef cannot be used to give alias names to pointers.
a) True
b) False

Answer: b
Explanation: The statement given in the question is incorrect. The keyword typedef can be used to give an alias name to all data types as well as pointers.

6. What is the size of myArray in the code shown below? (Assume that 1 character occupies 1 byte)

  x
x myArray

a) 5 bytes
b) 10 bytes
c) 40 bytes
d) 50 bytes

Answer: d
Explanation: The size of myArray will be equal to 50 bytes. In the code shown above, we have defined a character array x, of size 10. Hence the output of the code shown above is 10*5 = 50 bytes.

7. We want to declare x, y and z as pointers of type int. The alias name given is: intpt The correct way to do this using the keyword typedef is:
a)

    int typedef* intptr;
    int x,y,z;

b)

     typedef* intptr;
     int x,y,z;
    int typedef* intptr;
    intptr x,y,z;

d)

     typedef int* intptr;
     intptr x,y,z;
Answer: d
Explanation: It shows the correct way to declare x, y and z as pointers of type int using the keyword typedef. The advantage of using typedef with pointers is that we can declare any number of pointers in a single statement.
 
 

8. Consider this statement: typedef enum good {a, b, c} hello; Which of the following statements is incorrect about hello?
a) hello is a typedef of enum good
b) hello is a structure
c) hello is a variable of type enum good
d) the statement shown above is erroneous

Answer: a
Explanation: The keyword typedef is used to give an alternate name to an existing data type. Hence hello is the new name for enum good.

9. One of the major difference between typedef and #define is that typedef interpretation is performed by the _________________ whereas #define interpretation is performed by the _____________
a) pre-processor, compiler
b) user, pre-processor
c) compiler, pre-processor
d) compiler, user

Answer: c
Explanation: The major difference between typedef and #define is that the typedef interpretation is performed by the compiler whereas #define interpretation is performed by pre-processor.

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

 main

      a
    
         i
         ch
    hello
    hello u
    u.  
    u.  
     u. u.
     

a) 2, 3
b) 3, 2
c) 32
d) error

Answer: b
Explanation: In the code shown above, we have defined hello, which is the instance variable of a union (a) using typedef. On the execution of the code shown above, we obtain the output: 3, 2

This set of C MCQs focuses on “String Operations – 1”.

1. There are two groups of string functions defined in the header <string.h>. What are they?
a) first group names beginning with str; second group names beginning with mem
b) first group names beginning with str; second group names beginning with is
c) first group names beginning with string; second group names beginning with mem
d) first group names beginning with str; second group names beginning with type

Answer: a
Explanation: There are two groups of string functions declared under the header <string.h>. The first have names beginning with str and second have names beginning with mem.

2. What is the use of function char *strchr(ch, c)?
a) return pointer to first occurrence of ch in c or NULL if not present
b) return pointer to first occurrence of c in ch or NULL if not present
c) return pointer to first occurrence of ch in c or ignores if not present
d) return pointer to first occurrence of cin ch or ignores if not present

Answer: b
Explanation: The given code char *strchr(ch, c) return pointer to first occurrence of c in ch or NULL if not present.

3. Which code from the given option return pointer to last occurrence of c in ch or NULL if not present?
a) char *strchr(ch, c)
b) char *strrchr(ch, c)
c) char *strncat(ch, c)
d) char *strcat(ch, c)

Answer: b
Explanation: The function char *strrchr(ch, c) returns pointer to last occurrence of c in ch or NULL if not present.

4. Which among the given options compares atmost n characters of string ch to string s?
a) int strncmp(ch, s, n)
b) int strcmp(ch, s)
c) int strncmp(s, ch, n)
d) int strcmp(s, ch)

Answer: a
Explanation: int strncmp(ch, s, n) is used to compare at most n characters of string ch to string s; return <0 if ch0 of ch >s.

5. Which among the given options is the right explanation for the statement size_t strcspn(c, s)?
a) return length of prefix of s consisting of characters not in c
b) return length of prefix of s consisting of characters present in c
c) return length of prefix of c consisting of characters not in s
d) return length of prefix of c consisting of characters present in s

Answer: c
Explanation: The function size_t strcspn(c, s) is used to return length of prefix of c consisting of characters not in s.

6. The mem functions are meant for _______
a) returning a pointer to the token
b) manipulating objects as character arrays
c) returning a pointer for implemented-defined string
d) returning a pointer to first occurrence of string in another string

Answer: b
Explanation: The mem functions is used for manipulating objects as character arrays.

7. What is the function of void *memset(s, c, n)?
a) places character s into first n characters of c, return c
b) places character c into first n characters of s, return s
c) places character s into first n characters of c, return s
d) places character c into first n character of s, return c

Answer: b
Explanation: The void *memset(s, c, n) places character c into first n characters of s, return s.

8. Functions whose names begin with “strn”
a) manipulates sequences of arbitrary characters
b) manipulates null-terminated sequences of characters
c) manipulates sequence of non – null characters.
d) returns a pointer to the token

Answer: c
Explanation: Functions whose names begin with “strn” manipulates the sequence of non-null characters.

9. Which of the following is the right syntax to copy n characters from the object pointed to by s2 into the object pointed to by s1?
a) void *memcpy(void *s1,const void *s2,size_t n);
b) void *memcpy(void *s2, const void *s1, size_t n);
c) void memcpy(void *s1,const void *s2, size_t n);
d) void memcpy(void *s2,const void *s1,size_t n);

Answer: a
Explanation: The memcpy() function copies n characters from the object pointed to by s2 into the object pointed to by s1. If copying takes place between objects that overlap, the behavior is undefined.

10. What does the following function returns void *memmove(void *s1,const void s2, size_t n);?
a) returns the value of s1
b) returns the value of s2
c) doesn’t return any value
d) returns the value of s1 and s2

Answer: a
Explanation: The memmove() function copies n characters from the object pointed to by s2 into the object pointed to by s1.The memmove() function returns the value of s1.

This set of C MCQs focuses on “Character Handling – 1”.

1. Which header declares several functions useful for testing and mapping characters?
a) assert.h
b) stdio.h
c) ctype.h
d) errno.h

Answer: c
Explanation: The header <ctype.h> declares several functions useful for testing and mapping characters.

2. The______function tests for any character for which isalpha or isdigit is true.
a) isxdigit()
b) isspace()
c) isalnum()
d) isupper()

Answer: c
Explanation: int isalnum(int c)
The isalnum function tests for any character for which isalpha or isdigit is true.

3. What does the following C code do?

   c

a) checks if character is upper case
b) checks if character is lower case
c) tests for any control character
d) no function as such

Answer: c
Explanation:
int iscntrl( int c);
The iscntrl function tests for any control character.

4. What do the following C function do?

  c

a) tests for only space character
b) tests for only digit
c) tests for only lower case
d) tests for any printing character

Answer: d
Explanation: int isgraph(int c);
The isgraph function tests for any printing character except space.

5. The isdigit function tests for any decimal-digit character.
a) true
b) false

Answer: a
Explanation: int isdigit(int c);
This function checks whether the passed character is a decimal digit.

6. Which function returns true only for the characters defined as lowercase letters?
a) islow()
b) islower()
c) isalpa()
d) isalnum()

Answer: b
Explanation: int islower( int c);
The islower function tests for any character that is a lowercase letter.

7. This function checks whether the passed character is white-space.
a) ispunct()
b) isgraph()
c) isspace()
d) isalpha()

Answer: c
Explanation: The isspace function tests for any character that is a standard white-space character.

8. The standard white-space characters are the following: space (' '), form feed (' \ f '),
newline (' \n') , horizontal tab (' \tr), and vertlcal tab (' \v') can be tested with function.
a) ispunct()
b) isalpha()
c) isgraph()
d) isspace()

Answer: d
Explanation: The isspace function tests for any character that is a standard white-space character.

9. Which function tests for any character that is an uppercase letter.
a) iscntrl()
b) ispunct()
c) isdigit()
d) isupper()

Answer: d
Explanation: isupper() returns true only for the characters defined as uppercase letters.

10. The______function tests for any hexadecimal-digit character.
a) iscntrl()
b) ispunct()
c) isgraph()
d) isxdigit()

Answer: d
Explanation: int isxdigit( int c) ;
This function tests for any hexadecimal-digit character.

This set of C MCQs focuses on “Mathematical Functions – 1”.

1. Which of the following header declares mathematical functions and macros?
a) math.h
b) assert.h
c) stdmat. h
d) stdio. h

Answer: a
Explanation: The header file math.h declares all the mathematical functions and macros.

2. All the functions in this library take as a parameter and return as the output.
a) double, int
b) double, double
c) int, double
d) int, int

Answer: b
Explanation: All the function in this math library takes double as a parameter and gives double as the result.

3. HUGE_VAL macro is used when the output of the function may not be ___________
a) floating point numbers
b) integer number
c) short int
d) long int

Answer: a
Explanation: HUGE_VAL macro is used when the result of a function may not be representable as a floating point number.

4. What error occurs if an input argument is outside the domain over which the mathematical function is defined?
a) domain error
b) range error
c) no error
d) domain and range error

Answer: a
Explanation: A domain error occurs if an input argument is outside the domain over which the mathematical function is defined.

5. A range error occurs if the result of the function cannot be represented as a value.
a) int
b) short int
c) double
d) float

Answer: c
Explanation: if the result of the function cannot be represented as a double value, a range error occurs. If the result overflows (the magnitude of the result is so large that it cannot be represented in an object of the specified type), the function returns the value of the macro HUGE_VAL, with the same sign as the correct value of the function.

6. If the result overflows, the function returns the value of the macro HUGE_VAL, carrying the same sign except for the _________ function as the correct value of the function.
a) sin
b) cos
c) cosec
d) tan

Answer: d
Explanation: If the result overflows i.e the magnitude of the result is too large to be represented in an object of the specified type, the function returns the value of the macro HUGE_VAL, with the same sign except for the tan function as the correct value of the function.

7. If the result underflow, the function returns zero.
a) true
b) false

Answer: a
Explanation: If the result underflows i.e the magnitude of the result is very small to be represented in an object of the specified type, the function returns zero.

8. For the given math function, an error occurs if the arguments are not in the range [-1, +1].

double acos(double x);

a) range error
b) domain error
c) no error
d) domain and range error

Answer: b
Explanation: The acos() function is used to compute the principal value of the inverse of cosine of x. A domain error occurs for arguments not in the range [-1, +1].

9. Which function returns the arc sine in the range [-pi/2, +pi/2] radians?
a) arcsin()
b) asin()
c) sin()
d) asine()

Answer: b
Explanation: The asin() function is used to compute the principal value of the inverse of sine of x. A domain error occurs for arguments not in the range [-1, +1].

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

 x deg rad
x  
val    
deg   x  val
 x deg
Answer: a
Explanation: double atan(double x) returns the arc tangent of x in radians.

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Variable Argument Lists”.

1. How many macros are defined in the header file stdarg.h?
a) one
b) two
c) three
d) four

Answer: c
Explanation: The header file stdarg.h has three macros defined in it.

2. The header file stdarg.h defines a variable type ________
a) va_list
b) v_list
c) size_t
d) var_list

Answer: a
Explanation: The variable type declared under the header file stdarg.h is va_list. This holds information required by three macros.

3. The three macros defined by stdarg.h is _________
a) start(), arg() and end()
b) var_start(), var_arg() and var_end()
c) va_start(), va_arg() and va_end()
d) v_start(), v_arg() and v_end()

Answer: c
Explanation: The header file stdarg.h has three macros defined in it. They are va_start(), va_arg() and va_end(). va_list is a variable type that holds information needed by the three macros.

4. If access to the varying arguments is desired then the called function shall declare ________ having type va_list.
a) class
b) object
c) function
d) variable

Answer: b
Explanation: An object of type va_list has to be created in order to access the varying arguments.

5. Which macro retrieves the next argument in the parameter list of the function with type type?
a) type va_arg(va_list ap, type)
b) type var_arg(va_list ap, type)
c) type v_arg(va_list ap, type)
d) type val_arg(va_list ap, type)

Answer: a
Explanation: type va_arg(va_list ap,type)
This macro is used to retrieve the next argument in the parameter list of the function with type type.

6. The _______ macro shall be invoked before any access to the unnamed arguments.
a) va_arg
b) va_end
c) va_list
d) va_start

Answer: d
Explanation: va_start macro shall be invoked before any access to the unnamed arguments.void va-start (va-list ap, p); The va-start macro initializes ap for subsequent use by va-arg and va-end.

7. ______ macro must be called before using ______ and ________
a) va_arg, va_end and va_start
b) va_start, va_end and va_arg
c) va_end, va_arg and va_start
d) v_arg, v_end and v_start

Answer: b
Explanation: va_start macro must be called before using macros va_end and va_arg.
The macro void va_start(va_list p, last_arg) initializes p variable to be used with the va_arg and va_end macros.

8. The C library macro type _________ retrieves the next argument in the parameter list of the function with type.
a) va_end
b) va_arg
c) va_start
d) no macros

Answer: b
Explanation: va_arg is the C library macro defined under stdarg.h which retrieves the next argument in the parameter list of the function.

9. What is the role of the given C function?

 va_list ap

a) allows a function with variable arguments which used the va_start macro to return
b) retrieves the next argument in the parameter list
c) initializes ap variable to be used with the va_arg and va_start macros
d) returns the next additional argument as an expression

Answer: a
Explanation: void va_end(va_list ap) defined under the header file stdarg allows a function with variable arguments which used the va_start macro to return.
The result is undefined if va_end is not called before returning from the function.

10. Which header file should be included if a function has to be defined such that it can accept variable number of arguments?
a) stdlib.h
b) stdarg.h
c) assert.h
d) setjmp.h

Answer: b
Explanation: stdarg.h is the header file which should be included if a function has to be defined such that it can accept variable number of arguments.

This set of C MCQs focuses on “Static vs Dynamic Memory Allocation”.

1. Local variables are stored in an area called ___________
a) Heap
b) Permanent storage area
c) Free memory
d) Stack

Answer: d
Explanation: Local variables are stored in an area called stack. Global variables, static variables and program instructions are stored in the permanent storage area. The memory space between these two regions is known a heap.

2. The size of both stack and heap remains the same during run time.
a) True
b) False

Answer: b
Explanation: Memory can be allocated or de-allocated during the run time in the heap region. Memory bindings (allocation and de-allocation) are established and destroyed during the execution of the program. Hence we can see that the size of heap does not remain same during run time. However, the size of stack remains the same.

3. Choose the statement which is incorrect with respect to dynamic memory allocation.
a) Memory is allocated in a less structured area of memory, known as heap
b) Used for unpredictable memory requirements
c) Execution of the program is faster than that of static memory allocation
d) Allocated memory can be changed during the run time of the program based on the requirement of the program

Answer: c
Explanation: Execution of the program using dynamic memory allocation is slower than that using static memory allocation. This is because in dynamic memory allocation, the memory has to be allocated during run time. This slows down the execution of the program.

4. Which of the following header files must necessarily be included to use dynamic memory allocation functions?
a) stdlib.h
b) stdio.h
c) memory.h
d) dos.h

Answer: a
Explanation: stdlib.h is a header file which stands for the standard library. It consists of the declaration for dynamic memory allocation functions such as malloc(), calloc(), realloc() and free.

5. The type of linked list in which the node does not contain any pointer or reference to the previous node is _____________
a) Circularly singly linked list
b) Singly linked list
c) Circular doubly linked list
d) Doubly linked list

Answer: b
Explanation: A singly linked list is one in which each node has two fields, namely data field and pointer field. Data field stores the data and the pointer field points to the address of the next node.

6. Which of the following is an example for non linear data type?
a) Tree
b) Array
c) Linked list
d) Queue

Answer: a
Explanation: A data structure is said to be linear if its elements form a sequence or a linear list. For example array, linked list, queue, stack etc. Elements in a non linear data structure do not form a sequence. For example Trees, graphs etc.

7. Queue data structure works on the principle of ____________
a) Last In First Out (LIF0)
b) First In Last Out (FILO)
c) First In First Out (FIFO)
d) Last In Last Out (LILO)

Answer: c
Explanation: Queue is a linear data structure which works on the principle of first in first out. This means that the first element to be inserted in a queue will be the first one to be removed.

8. Which of the following is an example of static memory allocation?
a) Linked list
b) Stack
c) Queue
d) Array

Answer: d
Explanation: Array is an example of static memory allocation whereas linked list, queue and stack are examples for dynamic memory allocation.

9. Array is preferred over linked list for the implementation of ________
a) Radix sort
b) Insertion sort
c) Binary search
d) Polynomial evaluation

Answer: c
Explanation: When we try to implement binary search using linked list, the traversal steps per element increases in order to find the middle element. Thus, this process is slow and inefficient. This process is much faster using an array, hence it is preferable to use an array for the implementation of binary search.

10. The advantage of using linked lists over arrays is that ________
a) Linked list is an example of linear data structure
b) Insertion and deletion of an element can be done at any position in a linked list
c) Linked list can be used to store a collection of homogenous and heterogeneous data types
d) The size of a linked list is fixed

Answer: b
Explanation: Insertion and deletion in a linked list can be done at any position. On the other hand, in an array, to insert an element at a specific position, the rest of the elements have to be moved one position to the left and to delete an element, all the elements after the deleted element have to be moved one position to the right.

This set of C Interview Questions and Answers focuses on “DMA Functions, Memory Leak, Dangling Pointers – 2”.

1. What will be the output of the following C code if it is executed on a 32 bit processor?

 main

     p
    p   
     p
    p
     

a) 2
b) 4
c) 8
d) Junk value

Answer: b
Explanation: The size of a pointer is 2 bytes on a 16 bit platform, 4 bytes on a 32 bit platform and 8 bytes on a 64 bit platform.

2. The number of arguments taken as input which allocating memory dynamically using malloc() is ___________
a) 0
b) 1
c) 2
d) 3

Answer: b
Explanation: An example of memory allocated using malloc():
(int*)malloc(3*sizeof(int)
It is clear from the above example that malloc() takes only one argument as input, that is the number of bytes to be allocated.

3. Suppose we have a one dimensional array, named ‘x’, which contains 10 integers. Which of the following is the correct way to allocate memory dynamically to the array ‘x’ using malloc()?
a) x=(int*)malloc(10);
b) x=(int*)malloc(10,sizeof(int));
c) x=malloc(int 10,sizeof(int));
d) x=(int*)malloc(10*sizeof(int));

Answer: d
Explanation: According to the syntax of malloc, the correct way to do the specified operation is: x=(int*)malloc(10*sizeof(int)); This operation can also be performed using calloc(). In that case, the method will be: x=(int*)calloc(10,sizeof(int));

4. What will be the error (if any) in the following C code?

 main

     p
    p  
    p 
     p
    p
     

a) No error
b) Error in the statement: strcpy(p,”HELLO”);
c) Error in the statement: *p=(char)calloc(10);
d) Error in the statement: free(p);

Answer: c
Explanation: The syntax for dynamically allocating memory using calloc() is incorrect. Hence, this code results in an error. The correct syntax for calloc is: void*calloc(size_t n, size_t size);

5. If malloc() and calloc() are not type casted, the default return type is ___________
a) void*
b) void**
c) int*
d) char*

Answer: a
Explanation: If malloc() and calloc() are not type casted, they return a pointer of the type void.

6. Pick out the correct statement with respect to the heap.
a) Local variables are stored on the heap
b) Static variables are stored on the heap
c) Heap is the data structure which is used to implement recursive function calls
d) Everything on the heap is anonymous

Answer: a
Explanation: Local variables are stored on the stack. Static variables are stored in the permanent storage area. Stack is the data structure used to implement recursive function calls. Hence, it is true that everything on heap s anonymous.

7. What will be the output of the following C code? (Given that the size of array is 4 and new size of array is 5)

main

     piab
    
    a
    pa
    iiai
    i
    
    b
    pb
    iibi
    i
    p

a)

   1234
   12345

b) Error
c)

   0123
   01234
   0123
   12345
Answer: c
Explanation: In the above code, we are reallocating memory. When the size of the array is 4, the output is 0123. When the size of the array is changed to 5, the output is 01234. Hence, the output is:
0123
01234
 
 

8. When the pointer is NULL, then the function realloc is equivalent to the function ___________
a) malloc
b) calloc
c) free
d) alloc

Answer: a
Explanation: If pointer is NULL, the call to the function realloc is equal to malloc(size), for any value of size. If size is equal to zero, then the pointer is not NULL and the call is equivalent to free(pointer).

9. Garbage collector frees the programmer from worrying about ___________
a) Dangling pointers
b) Creating new objects
c) Memory leak
d) Segmentation errors

Answer: c
Explanation: A garbage collector is a program that automatically removes unwanted data held temporarily in the memory during processing. Hence it frees the programmer from worrying about memory leaks.

10. If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns ___________
a) NULL pointer
b) Zero
c) Garbage value
d) The number of bytes available

Answer: a
Explanation: A NULL pointer is returned when the memory allocated by malloc dynamically is insufficient.

This set of C MCQs focuses on “Pragma”.

1. The preprocessor directive used to give additional information to the compiler, beyond which is conveyed in the language _____________
a) #include
b) #define
c) #pragma
d) #elif

Answer: c
Explanation: The preprocessor directive #pragma is used to give additional information to the compiler, other than what is conveyed in the language itself.

2. What will be the output of the following C code, if it is run on a 32 bit platform?

 test

     i
     j

main

     test

a) Error
b) 1
c) 4
d) 8

Answer: d
Explanation: #pragma pack(n), where n is the number of alignment in bytes. #pragma pack(1) is the directive for the compiler to pack the structure.

3. In the directive, #pragma pack(n), which of the following is not a valid value of n?
a) 1
b) 2
c) 3
d) 4

Answer: c
Explanation: Valid arguments are 1,2,4 and 8. 3 is not a valid value for n.

4. Which of the following attributes is used to specify that the minimum required memory to be used to represent the types?
a) packed
b) aligned
c) unused
d) deprecated

Answer: a
Explanation: The keyword __attribute__ allows you to specify special attributes of struct type. 6 attributes are currently defined for types: aligned, packed, transparent_union, unused, deprecated and may_alias. The attribute “packed” is used to specify that the minimum required memory to be used to represent the types.

5. In the directive #pragma pack(n), if the value of ‘n’ is given to be 5, then what happens?
a) Error
b) Warning but no error
c) Executes the pragma statement
d) Ignores the pragma statement and executes the program

Answer: d
Explanation: Valid values for n are 1,2,4 and 8. If the value of n is one that the compiler does not recognize, then it simply ignores the pragma statement without throwing any error or warning.

6. The correct syntax of the attribute packed is _________
a) __attribute__((packed));
b) _attribute(packed);
c) _attribute_((packed));
d) __attribute__(packed);

Answer: a
Explanation: The correct syntax of the attribute packed is: __attribute__((packed));

7. The pragma ___________________ is used to remove an identifier completely from a program.
a) GNU piston
b) GCC poison
c) GNU poison
d) GCC piston

Answer: b
Explanation: There are several pragmas defines. One such pragma is GCC poison which is used to remove an identifier.

8. The function of __attribute__((packed)); can also be performed using _________
a) #pragma pack(1);
b) #pragma pack(2);
c) #pragma pack(4);
d) #pragma pack(8);

Answer: a
Explanation: __attribute((packed)); and #pragma(1) are used to perform the same function, that is, to direct the compiler to pack the structure.

9. #pragma GCC poison should be followed by a list of identifiers that are _________
a) even in number
b) odd in number
c) valid
d) invalid

Answer: d
Explanation: #pragma poison GCC is used to remove an identifier from a program. It should be followed by a list of identifiers which are not valid in the program, for example: scanf, printf etc.

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

main

    
     
Answer: a
Explanation: The code shown above results in an error: attempt to use poisoned printf
When the above program is compiled, it results in an error since #pragma was used to specify that the identifier printf should not be used in the program.

This set of C Multiple Choice Questions & Answers focuses on “Conditional Preprocessor Directives – 2”.

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

main

    
    
    
    san

a) 10
b) 20
c) Error
d) 1020

Answer: b
Explanation: In the code shown above, if the identifier san is defined, then its value is redefined and changed to 20. It is then printed. Hence the output is 20.

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

main

    
    
    
    
    
    hi
 

a) 4
b) 5
c) 45
d) error

Answer: a
Explanation: The code shown above illustrates #define, #ifdef, #else, #endif. Since the identifier hello is defined (condition of #if is true), another identifier names hi is defined and it’s value is 4. If hello was not defined, then the value of hi would be 5.

3. The purpose of the preprocessor directive #error is that ____________
a) It rectifies any error present in the code
b) It rectifies only the first error which occurs in the code
c) It causes the preprocessor to report a fatal error
d) It causes the preprocessor to ignore an error

Answer: c
Explanation: #error is a preprocessor directive which causes the preprocessor to report a fatal error. The tokens which form the rest of the line after #error are used as the error message.

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

main

    
    
    
    
    
    min

a) 10
b) 20
c) 30
d) error

Answer: c
Explanation: The output of the code shown above is 30. Since the identifier max is defined (the condition of #ifndef is true), hence another identifier, that is, min is defined and its value is equal to 30.

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

main

    
    
    
    
    
    
    hello

a) Error
b) 10
c) 100
d) 200

Answer: c
Explanation: The output of the code shown above is 100. If the identifier hello is defined, then it is undefined and redefined. It’s new value is 100. If the identifier was not defined, it would be defined with a value of 200.

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

main

    sf
        
    
    
        
        sf
    
    sf

a) 100
b) bad
c) 10
d) error

Answer: d
Explanation: The above code will result in an error because a macro cannot be defined using a simple assignment operator. In the code shown above, the value of sf is changed to 100 using the assignment operator. This causes an error.
 f

    
    sf

 main

    
    f
    sf

a) error
b) 100
c) 99
d) 10099

Answer: a
Explanation: Macro definition is global even if it is appears within the function scope. In this case the macro sf is defined in the function f(). Hence it results in a compile time error.

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

main

    
    
    
    
    
    
    

a) Euro
b) Rupee
c) Dollar
d) Error

Answer: c
Explanation: The output of the code shown above is Dollar. Since the macro CC is defined as US at the beginning of the code, it satisfies the condition #elif(CC==US). Hence “Dollar” is printed.

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

main

     a1
    a1sqr
    a1

a) 25
b) 1
c) 5
d) error

Answer: a
Explanation: The output of the code shown above is 25. This is because the arithmetic statement takes the form of: 25/5*5 (which is equal to 1). If the macro had been defined as #define sqr(x) (x*x), the output would have been 1.

10. Which of the following is not a preprocessor directive?
a) #error
b) #pragma
c) #if
d) #ifelse

Answer: d
Explanation: #ifelse is not a preprocessor directive. #error, #pragma, #if are preprocessor directives. There is a preprocessor directive, #elif, which performs the function of else-if.

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Inline”.

1. Name the function whose definition can be substituted at a place where its function call is made _________
a) friends function
b) inline function
c) volatile function
d) external function

Answer: b
Explanation: The inline function, whose definitions being small can be substituted at a place where its function call is made. They are inlined with their function calls.

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

  func1 a  b 

      a b

  func2 x

     xx

 main

     tmp
    func1
    tmp  func2
     tmp
     

a)

a=1 and b=4
square val = 36

b) a=4 and b=1
c) error
d) square val = 36

Answer: a
Explanation: The code shown above is an example of inline function. Both functions 1 and 2 are inline functions. Hence the output will be as shown in option
a=1 and b=4
square val = 36

.

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Recursion”.

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

main

     n
    nf1
    n

f1 x

     b
    x
         
    
        bxf1x
         b

a) 24
b) 4
c) 12
d) 10

Answer: a
Explanation: The above code returns the factorial of a given number using the method of recursion. The given number is 4 in the above code, hence the factorial of 4, that is, 24 will be returned.

2. The data structure used to implement recursive function calls _____________
a) Array
b) Linked list
c) Binary tree
d) Stack

Answer: d
Explanation: The compiler uses the data type stack for implementing normal as well as recursive function calls.

3. The principle of stack is __________
a) First in first out
b) First in last out
c) Last in first out
d) Last in last out

Answer: c
Explanation: A stack is a last in first out(LIFO) data type. This means that the last item to get stored in the stack is the first item to get out of it.

4. In the absence of a exit condition in a recursive function, the following error is given __________
a) Compile time error
b) Run time error
c) Logical error
d) No error

Answer: b
Explanation: When a recursive function is called in the absence of an exit condition, it results in an infinite loop due to which the stack keeps getting filled(stack overflow). This results in a run time error.

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

main

     ni
    nf
    n

f x

    x
             
    
    
        
        fx
    

a) ++++2
b) +++++2
c) +++++
d) 2

Answer: a
Explanation:
When x=6: ‘+’ is printed.
When x=5: ‘+’ is printed.
When x=4: ‘+’ is printed.
When x=3: ‘+’ is printed.
When x=2: 2 is printed.
Hence the output is: ++++2.

6. How many times is ‘a’ printed when the following C code is executed?

main

     a
    af1
    a

f1 b

    b
         
    
    
        
        f1b
    

a) 9 times
b) 10 times
c) 0 times
d) Infinite number of times

Answer: d
Explanation: Although we have specified the exit condition, the code above results in an infinite loop because we have used b- -(decrement operator) to call the recursive function. Due to this, the loop goes on infinitely. However, if we had used f1(b-1) instead, the answer would have been 10 times.

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

main

     n
     f n
    fn

 f n

    n
        nfn

a) 10
b) 80
c) 30
d) Error

Answer: c
Explanation: The recursive function returns n+f(n-2) till 10>0.
Therefore, the above code will be evaluated as: 10+8+6+4+2, which is equal to 30.

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

 main

    
    main
     

a) Hello is printed once
b) Hello infinite number of times
c) Hello is not printed at all
d) 0 is returned

Answer: b
Explanation: in the above code, we are calling main() from main(), which is recursion. However, we have not defined any condition for the program to exit. Hence, “hello” will be printed infinite number of times. To prevent this, we need to define a proper exit condition in the recursive function.

9. What will be the output of the following C code if the input given to the code shown below is “sanfoundry”?

main

     f
    
    f

 f

     c
    cNL

f
    c


a) sanfoundry
b) infinite loop
c) yrdnuofnas
d) fnasyrdnuo

Answer: c
Explanation: The above code prints the reverse of the word entered. The recursive function terminates when getchar() is equal to null.

10. Iteration requires more system memory than recursion.
a) True
b) False

Answer: b
Explanation: Recursion requires more system memory than iteration due to the maintenance of stack.