C Interview Questions and answers for fresher

Basics of C:

  1. What is C?

    • Answer: C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in the 1970s.
  2. What is the difference between int and float data types?

    • Answer: int is used for integer values, while float is used for floating-point (decimal) values.
  3. Explain the difference between printf() and scanf() functions.

    • Answer: printf() is used for output (printing to the console), while scanf() is used for input (reading from the console).

Variables and Data Types:

  1. What is a variable?

    • Answer: A variable is a named location in memory that stores a value.
  2. What is the size of the int data type in C?

    • Answer: The size of int varies by system architecture but is typically 4 bytes.
  3. Explain the sizeof operator.

    • Answer: sizeof returns the size, in bytes, of a variable or data type.

Control Flow:

  1. What is the purpose of the if statement in C?

    • Answer: The if statement is used for conditional execution of code based on a specified condition.
  2. Explain the difference between while and do-while loops.

    • Answer: while tests the condition before the loop, while do-while tests it after the loop.
  3. What is a switch statement used for?

    • Answer: A switch statement is used for multi-way branching based on the value of an expression.

Functions:

  1. What is a function in C?

    • Answer: A function is a block of code that performs a specific task.
  2. Explain the difference between actual parameters and formal parameters.

    • Answer: Actual parameters are passed to a function during a function call, while formal parameters are used within the function.
  3. What is recursion?

    • Answer: Recursion is a technique where a function calls itself directly or indirectly to solve a problem.

Arrays and Pointers:

  1. What is an array in C?

    • Answer: An array is a collection of elements of the same data type stored in contiguous memory locations.
  2. Explain the concept of a pointer.

    • Answer: A pointer is a variable that holds the memory address of another variable.
  3. How do you dynamically allocate memory in C?

    • Answer: Use the malloc() function to dynamically allocate memory.

Strings:

  1. What is a string in C?

    • Answer: A string is an array of characters terminated by a null character \0.
  2. How do you compare two strings in C?

    • Answer: Use the strcmp() function to compare two strings.

Structures and Unions:

  1. What is a structure in C?

    • Answer: A structure is a user-defined data type that groups related data members under one name.
  2. Explain the concept of a union.

    • Answer: A union is a user-defined data type that allows storing different data types in the same memory location.

File Handling:

  1. What is a file in C?

    • Answer: A file is a collection of data stored on a secondary storage device.
  2. How do you open a file in C?

    • Answer: Use the fopen() function to open a file.
  3. Explain the purpose of the fclose() function.

    • Answer: fclose() is used to close a file that was opened using fopen().

Memory Management:

  1. What is the purpose of the free() function?
    • Answer: free() is used to deallocate memory previously allocated by malloc() or related functions.

Preprocessor Directives:

  1. What is a preprocessor directive?

    • Answer: A preprocessor directive is a command that starts with a # symbol, and it is executed before the actual compilation.
  2. What is the purpose of #include in C?

    • Answer: #include is used to include the content of a file during the preprocessing stage.

Bitwise Operations:

  1. What are bitwise operations?

    • Answer: Bitwise operations manipulate individual bits of binary numbers.
  2. Explain the & (bitwise AND) operator.

    • Answer: & performs a bitwise AND operation.

Dynamic Memory Allocation:

  1. What is dynamic memory allocation in C?

    • Answer: Dynamic memory allocation allows a program to allocate memory at runtime.
  2. How do you allocate memory for an array dynamically?

    • Answer: Use the malloc() function.

Enumerations:

  1. What is an enumeration in C?
    • Answer: An enumeration is a user-defined data type that consists of named integer constants.

Miscellaneous:

  1. What is the purpose of the sizeof operator in C?

    • Answer: sizeof returns the size, in bytes, of a variable or data type.
  2. Explain the purpose of the const keyword.

    • Answer: const is used to declare constants, and it indicates that the variable's value cannot be changed.
  3. What is the difference between ++i and i++?

    • Answer: Both increment the value of i by 1, but ++i is the pre-increment operator, and i++ is the post-increment operator.
  4. Explain the typedef keyword.

    • Answer: typedef is used to create an alias for existing data types.
  5. What is the purpose of the return statement in a function?

    • Answer: The return statement is used to specify the value a function should return.
  6. What is the purpose of the break statement?

    • Answer: The break statement is used to exit from a loop or switch statement.
  7. Explain the difference between NULL and 0.

    • Answer: NULL is a macro representing a null pointer, while 0 is the integer literal zero.
  8. What is a comment, and how do you write comments in C?

    • Answer: Comments are explanatory notes in the code. In C, you can use // for single-line comments and /* */ for multi-line comments.
  9. What is the purpose of the continue statement?

    • Answer: The continue statement is used to skip the rest of the loop and move to the next iteration.
  10. Explain the concept of a constant pointer.

    • Answer: A constant pointer is a pointer whose address cannot be changed but the value it points to can be modified.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

80833