20 Sample Exam/Interview Questions for C Language

Here are 20 sample exam/interview questions and answers for C programming for bachelor studies:

  1. What is the difference between call by value and call by reference in C?
  • Call by value passes a copy of the argument to the function, while call by reference passes the address of the argument to the function, allowing the function to modify the original argument.
  1. What is a pointer in C?
  • A pointer in C is a variable that stores the memory address of another variable.
  1. How do you allocate memory dynamically in C?
  • Memory can be allocated dynamically in C using the malloc() or calloc() functions.
  1. What is the difference between malloc() and calloc() in C?
  • malloc() allocates memory and returns a pointer to the first byte of the allocated memory, while calloc() allocates memory for an array and returns a pointer to the first byte of the allocated memory, and also initializes all bytes to zero.
  1. What is a preprocessor directive in C?
  • A preprocessor directive in C is a statement that is executed by the preprocessor before the compilation of the program.
  1. What is the difference between a while loop and a do-while loop in C?
  • A while loop checks the condition before executing the loop, while a do-while loop executes the loop first and then checks the condition.
  1. What is the purpose of the break statement in C?
  • The break statement is used to exit a loop or a switch statement.
  1. What is the difference between the continue and goto statements in C?
  • The continue statement is used to skip the current iteration of a loop, while the goto statement is used to transfer control to a labeled statement.
  1. What is the difference between a local variable and a global variable in C?
  • A local variable is defined within a function and is only accessible within that function, while a global variable is defined outside of any function and is accessible throughout the entire program.
  1. What is the difference between a single-dimensional array and a multi-dimensional array in C?
  • A single-dimensional array is an array with one dimension, while a multi-dimensional array is an array with more than one dimension.
  1. What is a structure in C?
  • A structure in C is a user-defined data type that groups together different data types.
  1. How do you pass a structure to a function in C?
  • A structure can be passed to a function by passing a pointer to the structure as an argument.
  1. What is the difference between a union and a structure in C?
  • A union shares the same memory location for multiple variables, while a structure has separate memory locations for each variable.
  1. What is the difference between a static variable and a global variable in C?
  • A static variable is initialized only once and retains its value between function calls, while a global variable is initialized once at program startup and retains its value throughout the entire program.
  1. What is the difference between a string literal and a string variable in C?
  • A string literal is a constant string stored in memory, while a string variable is a variable that can store a string.
  1. How do you input and output data in C?
  • Data can be input and output in C using the scanf() and printf() functions, respectively.
  1. What is the difference between the ++ and -- operators in C?
  • The ++ operator increments a variable by 1, while the -- operator decrements a variable by 1.
  1. What is the difference between the & and * operators in C?
  • The & operator is used to get the address of a variable, while the * operator is used to get the value stored at a memory address.
  1. What is a header file in C?
  • A header file in C is a file that contains function declarations, macro definitions, and other constructs that can be shared among multiple source files.
  1. What is the difference between the #include and #define preprocessor directives in C?
  • The #include directive is used to include the contents of a header file in the source file, while the #define directive is used to define a macro.

Please keep in mind that these questions and answers are just a sample and are not exhaustive. Additionally, I suggest double-checking the answers and also checking the latest C standards and best practices as the field is constantly evolving.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.